Lazarus
Programming => Graphics => Graphics and Multimedia => BGRABitmap and LazPaint => Topic started by: gregbug on June 01, 2012, 12:39:49 am
-
Hi! guys! i'm Gianluca from italy!!!
i'm using lazarus and BGRABitmap for make a freeware tool for Gideros SDK mobile...
i copy a portion of image from a TPicture (it's a PNG with transparency) in a TBGRABitmap then flip it (on horizontal or vertical axes if needed) then copy back in a TPicture Box...
in windows 7 all is working perfect.!!!
but on osx (lion) the copied image is corrupted!
the code in TPaintBox "OnPaint" is:
procedure TfrmMain.imagePreviewPaint(Sender: TObject);
var
xPos, yPos: Integer;
w, h: integer;
begin
if fcurrentSprite <> nil then
begin
xPos := ((scrlImage.Width div 2) - (fcurrentSprite.w div 2));
yPos := ((scrlImage.Height div 2) - (fcurrentSprite.h div 2));
animProject.preview.SetSize(fcurrentSprite.w, fcurrentSprite.h);
//animProject.preview.Bitmap.Clear;
animProject.preview.Canvas.CopyRect(
Rect(0, 0, fcurrentSprite.w, fcurrentSprite.h), AnimProject.TexturePack.Bitmap.Canvas,
Rect(fcurrentSprite.x, fcurrentSprite.y, fcurrentSprite.x + fCurrentSprite.w, fcurrentSprite.y + fCurrentSprite.h));
if fCurrentSprite.flipX then begin
animProject.preview.HorizontalFlip;
end;
if fCurrentSprite.flipY then begin
end;
animProject.preview.draw(imagePreview.Canvas, xPos, yPos, false);
end;
end;
any ideas? it's my bug ?
thanks!..
windows output: (that's fine):
(http://s19.postimage.org/vkft947kv/Snapshot_1.jpg) (http://postimage.org/image/vkft947kv/)
osx Lion: (that's corrupted)
(http://s9.postimage.org/7i6gsnmdn/Schermata_06_2456080_alle_00_29_03.jpg) (http://postimage.org/image/7i6gsnmdn/)
PS: testet with lazarus "official" and last build (31/5) and BGRABitmap rev. 387 (that compile on osx lion with no errors)
please help!!!
thanks again,
Gianluca.
-
I have similar problem with time ago
http://www.lazarus.freepascal.org/index.php/topic,12411.msg68109.html#msg68109
resolved by using TImage...
-
Maybe it would be necessary to create a special implementation for MacOS, like BGRAWinBitmap. But anyway, using Canvas for handling transparent bitmaps is not recommended. The Canvas property is only here to provide compatible functions for drawing with Brush and Pen, but should be avoided as much as possible. It can slow down your application too because using Canvas property need to create a TBitmap, and then this bitmap needs to be converted back to BGRABitmap data. CanvasBGRA property is there to provide these functions, but with transparency and antialiasing, and no implicit conversion.
Can you load initially the Png image directly into a TBGRABitmap ? So that you can then copy it in your preview using PutImage with dmSet drawing mode. Alternatively, you can assign a TBitmap to a BGRABitmap that will contain your image.
-
thanks guys!!! for give time to me! :)
Maybe it would be necessary to create a special implementation for MacOS, like BGRAWinBitmap. But anyway, using Canvas for handling transparent bitmaps is not recommended. The Canvas property is only here to provide compatible functions for drawing with Brush and Pen, but should be avoided as much as possible. It can slow down your application too because using Canvas property need to create a TBitmap, and then this bitmap needs to be converted back to BGRABitmap data. CanvasBGRA property is there to provide these functions, but with transparency and antialiasing, and no implicit conversion.
Can you load initially the Png image directly into a TBGRABitmap ? So that you can then copy it in your preview using PutImage with dmSet drawing mode. Alternatively, you can assign a TBitmap to a BGRABitmap that will contain your image.
@circular
yes i can load png directly into tBGRABitmap...
coding now...
i keep you informaed... thanks again!! :)
-
ok. i think that the problem (under osx) is in "CopyRect"
now i loading main png in TBGRABitmap then i need to copy only a portion of this image into the tPaintBox and i use
CopyRect... and in osx the image is corrupted...
if i use putImage (but how can i copy only a portion of image without copyrect?) the image is perfect...
i miss something ? :-\
please help! :) :-\
-
solved:
this copy work also on osx...
procedure copyRectGFX(xPos, yPos, width, height: integer; var Source, Destination: TBGRABitmap);
var
x, y: integer;
xd, yd: integer;
begin
xd := 0; yd := 0;
for y := yPos to yPos + height do begin
for x := xPos to xPos + width do begin
destination.CanvasBGRA.GammaExpandedPixels[xd, yd] := source.CanvasBGRA.GammaExpandedPixels[x, y];
inc(xd);
end;
xd := 0;
inc(yd);
end;
end;
...
-
That is the slow way.
If you want to draw a portion that has size (sx,sy) into a bitmap of size (sx,sy), and that the upper coordinate in the source bitmap is (x,y), you can do :
dest := TBGRABitmap.Create(sx,sy);
dest.PutImage(-x,-y, source, dmSet);
...
dest.Free;
Maybe I should make a CopyRect procedures that does that.
In the meantime, you can use GetPart :
dest := source.GetPart(rect(x,y,x+sx,y+sy));
Which creates a new bitmap containing the portion you want.
-
I've added PutImagePart, which is an optimized way for doing PutImage(GetPart(.Free)), and also added CopyRect(x,y,...) in CanvasBGRA.
I notice that there is already CopyRect(Rect,...) in CanvasBGRA.
-
@circular
thanks for your fast support and help!
thnaks again.
Gianluca.