Here's a sample code that flips the bitmap vertical or horizontal
and creates a new bitmap:
~~~~~~~~~~~~~~~~~~~~~~~~~
{
Usage:
BitmapFlip(True,
False,
Image1.Picture.Bitmap,
Image1.Picture.Bitmap
) ;
}
interface
Uses Windows,Graphics;
Function BitmapFlip(
___Const Vertical : Boolean;
___Const Horizontal : Boolean;
var BitmapIn : TBitmap;
___ out BitmapOut : TBitmap): Boolean;
implementation
Type
___TColorData = Array[0..128000] Of TRGBTriple;
___pColorData = ^TColorData;
Function BitmapFlip( Const Vertical : Boolean;
_____________________Const Horizontal : Boolean;
var BitmapIn : TBitmap;
___out BitmapOut : TBitmap): Boolean;
Var DataIn : pColorData;
___DataOut : pColorData;
___inRow : Integer;
___inCol : Integer;
Begin
___Result := False;
___Try
___If BitmapIn.PixelFormat <> pf24bit Then Exit;
___With BitmapOut Do
___Begin
______Width := BitmapIn.Width;
______Height := BitmapIn.Height;
______PixelFormat := BitmapIn.PixelFormat;
___End;
___For inRow := 0 To BitmapIn.Height - 1 Do
___Begin
______DataIn := BitmapIn.Scanline[inRow];
______If Vertical Then
______Begin
_________DataOut := BitmapOut.ScanLine
_________[BitmapIn.Height - 1 - inRow];
______End
___Else
___Begin
______DataOut := BitmapOut.ScanLine[inRow];
___End;
___If Horizontal Then
___Begin
______For inCol := 0 To BitmapIn.Width-1 Do
_________DataOut[inCol] := DataIn[BitmapIn.Width-1-inCol];
___End
___Else
___Begin
______For inCol := 0 To BitmapIn.Width-1 Do
______DataOut[inCol] := DataIn[inCol];
___End;
___End;
______Result := True;
___Except
___End;
End;
End.
~~~~~~~~~~~~~~~~~~~~~~~~~
and creates a new bitmap:
~~~~~~~~~~~~~~~~~~~~~~~~~
{
Usage:
BitmapFlip(True,
False,
Image1.Picture.Bitmap,
Image1.Picture.Bitmap
) ;
}
interface
Uses Windows,Graphics;
Function BitmapFlip(
___Const Vertical : Boolean;
___Const Horizontal : Boolean;
var BitmapIn : TBitmap;
___ out BitmapOut : TBitmap): Boolean;
implementation
Type
___TColorData = Array[0..128000] Of TRGBTriple;
___pColorData = ^TColorData;
Function BitmapFlip( Const Vertical : Boolean;
_____________________Const Horizontal : Boolean;
var BitmapIn : TBitmap;
___out BitmapOut : TBitmap): Boolean;
Var DataIn : pColorData;
___DataOut : pColorData;
___inRow : Integer;
___inCol : Integer;
Begin
___Result := False;
___Try
___If BitmapIn.PixelFormat <> pf24bit Then Exit;
___With BitmapOut Do
___Begin
______Width := BitmapIn.Width;
______Height := BitmapIn.Height;
______PixelFormat := BitmapIn.PixelFormat;
___End;
___For inRow := 0 To BitmapIn.Height - 1 Do
___Begin
______DataIn := BitmapIn.Scanline[inRow];
______If Vertical Then
______Begin
_________DataOut := BitmapOut.ScanLine
_________[BitmapIn.Height - 1 - inRow];
______End
___Else
___Begin
______DataOut := BitmapOut.ScanLine[inRow];
___End;
___If Horizontal Then
___Begin
______For inCol := 0 To BitmapIn.Width-1 Do
_________DataOut[inCol] := DataIn[BitmapIn.Width-1-inCol];
___End
___Else
___Begin
______For inCol := 0 To BitmapIn.Width-1 Do
______DataOut[inCol] := DataIn[inCol];
___End;
___End;
______Result := True;
___Except
___End;
End;
End.
~~~~~~~~~~~~~~~~~~~~~~~~~
No comments:
Post a Comment