Board index » delphi » Flip bitmaps

Flip bitmaps


2004-06-14 02:11:36 PM
delphi177
Hi,
Is there a rtl or api function to flip a bitmap image?
Thanks,
RSK.
 
 

Re:Flip bitmaps

Hi,
Here is my routine to do flipping using the windows strechdraw routine.
Hope this helps.
I have heard varius stories about failure of the below technik but I
haven't encounter any my self. It is said that because this technick
is using the stretch draw it is driver dependent which meens that in
some graphic cards it might not work as expected. I haven't seen any
problems until now but then again I am using it internally only.
Type
TMirror = (mtHorizontal, mtVertical, mtBoth);
procedure Mirror(Picuter: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
//SpiegelnVertikal(MemBmp);
//SpiegelnHorizontal(MemBmp);
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;
Regards
Yannis.
"RSK" <XXXX@XXXXX.COM>wrote in
Quote
Hi,
Is there a rtl or api function to flip a bitmap image?

Thanks,
RSK.


 

Re:Flip bitmaps

Hi Yannis,
Thank you for your help,
best regards,
RSK.
"Yannis" <XXXX@XXXXX.COM>writes
Quote
Hi,

Here is my routine to do flipping using the windows strechdraw routine.
Hope this helps.

I have heard varius stories about failure of the below technik but I
haven't encounter any my self. It is said that because this technick
is using the stretch draw it is driver dependent which meens that in
some graphic cards it might not work as expected. I haven't seen any
problems until now but then again I am using it internally only.

Type
TMirror = (mtHorizontal, mtVertical, mtBoth);

procedure Mirror(Picuter: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
//SpiegelnVertikal(MemBmp);
//SpiegelnHorizontal(MemBmp);
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;

Regards
Yannis.

"RSK" <XXXX@XXXXX.COM>wrote in
news:XXXX@XXXXX.COM:

>Hi,
>Is there a rtl or api function to flip a bitmap image?
>
>Thanks,
>RSK.
>
>