Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
How to flip a bitmap image
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Question:
Is there a RTL or API function to flip a bitmap image?
Answer:
You can use the Windows function StrechBlt() to help you with this. Some older versions of Windows (Windows 3.1, Windows 95) had problems with the graphic card drivers for these functions.
I myself had a Diamond Stealth (or was it a Diamond Speedstar?) where this Windows function was not implemented properly in the Windows 95 driver. There is another Win API function for it.. for device independant bitmaps - it is called StretchDIBits(), but StretchBlt() is faster.
And nowadays (June 2004), all graphic cards should be supported properly.  | |  | | type
TMirror = (mtHorizontal, mtVertical, mtBoth );
procedure Mirror(Picture: TPicture; MirrorType: TMirror);
var
MemBmp: Graphics.TBitmap;
Dest: TRect;
begin
if Assigned(Picture.Graphic) then
begin
MemBmp := Graphics.TBitmap.Create;
try
MemBmp.PixelFormat := pf24bit;
MemBmp.HandleType := bmDIB;
MemBmp.Width := Self.Picture.Graphic.Width;
MemBmp.Height := Self.Picture.Height;
MemBmp.Canvas.Draw(0, 0, Picture.Graphic);
case MirrorType of
mtHorizontal:
begin
Dest.Left := MemBmp.Width;
Dest.Top := 0;
Dest.Right := -MemBmp.Width;
Dest.Bottom := MemBmp.Height
end;
mtVertical:
begin
Dest.Left := 0;
Dest.Top := MemBmp.Height;
Dest.Right := MemBmp.Width;
Dest.Bottom := -MemBmp.Height
end;
mtBoth:
begin
Dest.Left := MemBmp.Width;
Dest.Top := MemBmp.Height;
Dest.Right := -MemBmp.Width;
Dest.Bottom := -MemBmp.Height
end;
end;
StretchBlt(MemBmp.Canvas.Handle, Dest.Left, Dest.Top, Dest.Right, Dest.Bottom,
MemBmp.Canvas.Handle, 0, 0, MemBmp.Width, MemBmp.Height,
SRCCOPY);
Picture.Graphic.Assign(MemBmp);
Invalidate
finally
FreeAndNil(MemBmp)
end;
end;
end;
| |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|