Lazarus
Programming => Graphics and Multimedia => Graphics => Topic started by: Jo on November 18, 2007, 12:01:22 pm
-
Is there a way to draw transparent bitmaps? The example for win32 using writing and reading from TMemoryStream gives on wince the following: “Failed to get raw image description from bitmap”. Any ideas how I can go about this?
-
This should work, do you have a code example ?
-
Just copied and adjusted the example. The error is when writing the bitmap to the stream, and the bitmap is drawn correctly if I don't use transparency and streams:
procedure TForm1.Button2Click(Sender: TObject);
var
buffer: THandle;
bmp: TBitmap;
memstream: TMemoryStream;
begin
bmp := TBitmap.Create;
bmp.Width:=32;
bmp.Height:=32;
//bmp.PixelFormat:=pf24Bit ;
Handle := LoadBitmap(hInstance, 'test');
if (buffer = 0) then exit; // Error loading the bitmap
bmp.Handle := buffer;
memstream := TMemoryStream.create;
try
bmp.SaveToStream(memstream);
memstream.position := 0;
bmp.LoadFromStream(memstream);
finally
memstream.free;
end;
bmp.Transparent := True;
bmp.TransparentColor := clblack;
Canvas.Draw(100, 150, bmp);
bmp.Free; // Release allocated resource
end;
-
Changing pixelformat doesn't work yet. Only pfDevice is supported.
BTW, I hope this is a typo: Handle := LoadBitmap(hInstance, 'test');
I would expectbuffer := LoadBitmap(hInstance, 'test');
-
BTW, I hope this is a typo:
Yes, it was from testing bmp.Handle:=...
The code works fine on win32 compilation but the wince creates the error when writting the bitmap to the stream at:
bmp.SaveToStream(memstream);
-
ok, can you bugrep this, with sample code and sample image (otherwise this might get forgotten)
-
ok.