Recent

Author Topic: transparent bitmaps  (Read 9913 times)

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
transparent bitmaps
« 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?

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
RE: transparent bitmaps
« Reply #1 on: November 19, 2007, 11:52:11 am »
This should work, do you have a code example ?
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
RE: transparent bitmaps
« Reply #2 on: November 19, 2007, 01:22:18 pm »
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;

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
RE: transparent bitmaps
« Reply #3 on: November 19, 2007, 02:36:30 pm »
Changing pixelformat doesn't work yet. Only pfDevice is supported.

BTW, I hope this is a typo:
Code: [Select]
Handle := LoadBitmap(hInstance, 'test');
I would expect
Code: [Select]
buffer := LoadBitmap(hInstance, 'test');
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
RE: transparent bitmaps
« Reply #4 on: November 19, 2007, 04:18:42 pm »
Quote

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);

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
RE: transparent bitmaps
« Reply #5 on: November 19, 2007, 04:52:47 pm »
ok, can you bugrep this, with sample code and sample image (otherwise this might get forgotten)
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
RE: transparent bitmaps
« Reply #6 on: November 20, 2007, 09:22:19 am »
ok.

 

TinyPortal © 2005-2018