画像をシフトするサンプルコード
画像をシフトするサンプルです。ソースコードはDelphi5で作成しましたがその他の言語でも流用できるかと思います。
画像処理の結果
シフトの処理を行うと下図のようになります。
 
 
ソースコード
[EffectBass.pas]
//Bass Unit unit EffectBass; interface uses Windows,SysUtils, Classes, Graphics; type //24bitアクセス用ポインタ pRGBarray = ^TRGBarray; TRGBarray = array[0..0] of TRGBTriple; //None リテラル type //24bitアクセス用ダブルポインタ PPBits = ^TPBits; TPBits = array[0..0] of pRGBarray; //None リテラル //汎用プロシージャ procedure Set24bit(Src,Dest :TBitmap); function Set255(Value : integer) : BYTE; implementation ///////// procedure Set24bit(Src,Dest :Tbitmap); begin Src.PixelFormat :=pf24bit; Dest.PixelFormat:=pf24bit; Dest.Width:=Src.Width; Dest.Height:=Src.Height; end; ///////// function Set255(Value:Integer):Byte; begin if Value>=255 then Result:=255 else if Value<=0 then Result:=0 else Result:=Value; end; end.
[シフトの関数]
//-----------------------------------------------------------------------------
// ■関数名    EffectShift
// ■用途      イメージをシフトする
// ■引数
//             hBMP             ...転送元のTBitmapのハンドル
//             nWidth           ...0~Widthまで
//             nHeight          ...0~Heightまで
//■戻り値
//             ビットマップのハンドル
// -----------------------------------------------------------------------------
function EffectShift(hBMP:HBitmap;nWidth,nHeight: integer):HBitmap;
var
  Row,Col,hoge,foo : Integer;
  SrcRow,DestRow   : pRGBArray;
  _Height,_Width   : integer;
  SrcBitmap,DestBitmap : TBitmap;
begin
 SrcBitmap   :=TBitmap.Create;
 DestBitmap  :=TBitmap.Create;
 SrcBitmap.Handle  :=hBMP;
 //範囲チェック
 if (nWidth>SrcBitmap.Width)  or (nHeight>SrcBitmap.Height) then
 begin
    Result :=SrcBitmap.ReleaseHandle;
    SrcBitmap.Free ;
    DestBitmap.Free;
    Exit;
 end;
 Set24bit(SrcBitmap,DestBitmap);
 _Height := SrcBitmap.height-1;
 _Width  := SrcBitmap.width-1;
 hoge:=nWidth;  foo:=nHeight;
try
   For Row := 0 To _Height   do
   begin
       SrcRow:=SrcBitmap.ScanLine[Row];
       if foo>_Height then foo:=0;
       DestRow:=DestBitmap.ScanLine[foo];
        For Col := 0 To _Width do
        begin
             if (hoge> _Width) then hoge:=0;
             DestRow[hoge].rgbtBlue:=SrcRow[Col].rgbtBlue;
             DestRow[hoge].rgbtGreen:= SrcRow[Col].rgbtGreen;
             DestRow[hoge].rgbtRed:=SrcRow[Col].rgbtRed;
             inc(hoge);
       end;
      inc(foo);
    end;
  Result :=DestBitmap.ReleaseHandle;
except
     Result :=SrcBitmap.ReleaseHandle;
end;
  SrcBitmap.Free ;
  DestBitmap.Free;
end;
[関数の呼び出し]
  procedure TForm1.Button1Click(Sender: TObject);
  begin
    Image1.Picture.bitmap.Handle:= 関数名(Image1.Picture.Bitmap.ReleaseHandle);
  end;
スポンサーリンク
      
      
      
      
      
    
関連記事
| 前の記事: | 画像を四つの鏡へ変換するサンプルコード | 
| 次の記事: | 画像の明るさを調整するサンプルコード | 
公開日:2015年02月18日 最終更新日:2015年02月19日
記事NO:00232 
プチモンテ ※この記事を書いた人
|  | |
|  | 💻 ITスキル・経験 サーバー構築からWebアプリケーション開発。IoTをはじめとする電子工作、ロボット、人工知能やスマホ/OSアプリまで分野問わず経験。 画像処理/音声処理/アニメーション、3Dゲーム、会計ソフト、PDF作成/編集、逆アセンブラ、EXE/DLLファイルの書き換えなどのアプリを公開。詳しくは自己紹介へ | 
| 🎵 音楽制作 BGMは楽器(音源)さえあれば、何でも制作可能。歌モノは主にロック、バラード、ポップスを制作。歌詞は抒情詩、抒情的な楽曲が多い。楽曲制作は🔰2023年12月中旬 ~ | |

 
        



 
  
 


