画像を右回転90℃するサンプルコード
画像を右回転90℃するサンプルです。ソースコードはDelphi5で作成しましたがその他の言語でも流用できるかと思います。
画像処理の結果
右回転90℃の処理を行うと下図のようになります。
ソースコード
[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.
[右回転90℃の関数]
//----------------------------------------------------------------------------- //■関数 EffectsTurn90 //■用途 画像を右回転(90℃)する //■引数 hBMP ...転送元のビットマップのハンドル //■戻り値 // 新しいビットマップのハンドル //----------------------------------------------------------------------------- function EffectsTurn90(hBMP :HBitmap):HBitmap; var Row,Col : Integer; SrcRow : pRGBArray; SrcBitmap,DestBitmap : TBitmap; DestBits : PPBits; begin SrcBitmap :=TBitmap.Create; DestBitmap :=TBitmap.Create; SrcBitmap.handle :=hBMP; SrcBitmap.PixelFormat:=pf24bit; DestBitmap.Width:= SrcBitmap.Height; DestBitmap.Height:=SrcBitmap.Width; DestBitmap.PixelFormat:=pf24bit; GetMem(DestBits, DestBitmap.Height * SizeOf(pRGBArray)); try for Row:= 0 to DestBitmap.Height - 1 do DestBits[Row]:=DestBitmap.Scanline[Row]; for Row:=0 to SrcBitmap.Height-1 do begin SrcRow:=SrcBitmap.ScanLine[Row]; for Col:=0 to SrcBitmap.Width-1 do begin //右90度回転 DestBits[Col][SrcBitmap.Height-1-Row].rgbtBlue :=SrcRow[Col].rgbtblue; DestBits[Col][SrcBitmap.Height-1-Row].rgbtGreen :=SrcRow[Col].rgbtGreen; DestBits[COl][SrcBitmap.Height-1-Row].rgbtred :=SrcRow[Col].rgbtred; end; end; FreeMem(DestBits); DestBits:=nil; Result :=DestBitmap.ReleaseHandle; except if Assigned(DestBits) then FreeMem(DestBits); 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:00225