Recent

Author Topic: why does png lose transparency on triple buffer or stretch?  (Read 9155 times)

jw

  • Full Member
  • ***
  • Posts: 120
why does png lose transparency on triple buffer or stretch?
« on: March 21, 2010, 07:36:53 pm »
ok If I make 2 sprite buffers like so

spritenormal : TCustomBitmap;
spritestretched : TCustomBitmap;

spritenormal:= TPortableNetworkGraphic.Create;
spritestretched:= TPortableNetworkGraphic.Create;

and load sprite normal form a timagelist like so
spriteimages.GetBitmap(0, spritenormal);

then do a stretch to fit multiple screen resolution
spritestretched.Canvas.StretchDraw(rect(0,0,screen.width*0.50,screen.height*0.50),spritenormal);

then draw it to the form canvas like so
Canvas.Draw(0,0, spritestretched);

I lose the transparency of the ping in the stretchdraw command,
but of I decide to just display the loaded spritenormal it works fine?
how do I fix this??????

                              
« Last Edit: March 21, 2010, 07:39:35 pm by jw »

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2510
Re: why does png lose transparency on triple buffer or stretch?
« Reply #1 on: March 21, 2010, 10:44:11 pm »
Drawing alpha is limited supported. When loading from images, a canvas has alpha, but as soon as you draw on it, the (destination) canvas looses alpha.
Just think of it, how do you want to make a difference in drawing in the following examples:
1) draw an alpha image on an exiting background, so the image blends
2) draw an alpha image on an exiting background, so the image replaces

At this moment, the LCL only does 1.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

jw

  • Full Member
  • ***
  • Posts: 120
Re: why does png lose transparency on triple buffer or stretch?
« Reply #2 on: March 22, 2010, 12:26:21 am »
is there a hex value I can put into $????????; that will paint the canvas background transparent with a draw command?

Canvas.pen.Color := $????????;
Canvas.brush.Color := $????????;
Canvas.rectangle(0,0,width,Height);

if no!!!!
Then is there a way to stretch without doing the stretchdaw?
lf I'm pulling an image from a timiagelist can it be stretched within the timagelist during runtime before it's loaded into the tcustombitmap?
« Last Edit: March 22, 2010, 12:39:56 am by jw »

circular

  • Hero Member
  • *****
  • Posts: 3359
    • Personal webpage
Re: why does png lose transparency on triple buffer or stretch?
« Reply #3 on: March 22, 2010, 12:40:08 am »
With my lib ( http://consume.o2switch.net/lazarus/bgrabitmap.zip ) you can do it this way :
Code: [Select]
var OriginalBitmap, StretchedBitmap: TBGRABitmap;
begin
  OriginalBitmap := TBGRABitmap.Create('some_image.png');
  StretchedImage := TBGRABitmap(OriginalBitmap.Resample(200,200));
  StretchedImage.Draw(Canvas,0,0,False);
end;
Conscience is the debugger of the mind

jw

  • Full Member
  • ***
  • Posts: 120
Re: why does png lose transparency on triple buffer or stretch?
« Reply #4 on: March 23, 2010, 03:57:17 pm »
wow circular you're far beyond my codeing skills.  I'll check out the library but for now I still want to deal with the LCL and learn it.  My thinking is that the LCL will do what I want because you can do an image stretch within a timagelist without loseing transparency.  I just can't find the command to to it.


example I have a transparent image in a tcustombitmap and don't use any draw commands on it then I should be able to make another timage list for the stretching.  

Modifing the original post

ok If I make a sprite buffer like so

sprite : TCustomBitmap;

sprite:= TPortableNetworkGraphic.Create;
 

and load the unstretched sprite from a timagelist like so
spriteimages.GetBitmap(0, spritenormal);

then do a stretch to fit multiple screen resolution using a timagelistbuffer

timagelistbuffer.width:=screen.width*0.50
timagelistbuffer.height:=screen.height*0.50;


how do you get  stretch from runtime with a timagelist??

timangelistbuffer.stretch:=true;         //this errors
timangelistbuffer.Insert(0, sprite, stretch);  //this errors
timangelistbuffer.Insert(0, sprite, nil); //this loads but no stretch

pull the stretched image back into the sprite
 
timagelistbufferbuffer.GetBitmap(0, sprite);
 
 

then draw it to the form canvas like so
Canvas.Draw(0,0, sprite);
 
« Last Edit: March 23, 2010, 04:07:43 pm by jw »

jw

  • Full Member
  • ***
  • Posts: 120
Re: why does png lose transparency on triple buffer or stretch?
« Reply #5 on: March 23, 2010, 09:52:32 pm »
the command that worked was

timagelist.insertmasked(index,tcustombitmap,mask color);

now I can stretch all my sprites then reclaim transpareny through an imagelist and a backgroud color mask.

circular

  • Hero Member
  • *****
  • Posts: 3359
    • Personal webpage
Re: why does png lose transparency on triple buffer or stretch?
« Reply #6 on: March 24, 2010, 09:04:59 pm »
In fact you can directly draw an image from the TImageList with the Draw method, but I guess the transparency is only 1-bit. I mean that there can be opaque pixels or transparent pixels but nothing between the two.
Conscience is the debugger of the mind

jw

  • Full Member
  • ***
  • Posts: 120
Re: why does png lose transparency on triple buffer or stretch?
« Reply #7 on: April 13, 2010, 09:59:37 pm »
circular
 
how are you pulling the image directly from a timamgelist with a draw command?


I first have to put the image into a tcutombitmap buffer then stretchdraw it to another tcustombitmap.

It would be nice to skip a step.

this is the only command I know of to get the image out
timagelist.getbitmap(1,tcustombitmapbuffer)

then stretch it

circular

  • Hero Member
  • *****
  • Posts: 3359
    • Personal webpage
Re: why does png lose transparency on triple buffer or stretch?
« Reply #8 on: April 14, 2010, 11:25:26 am »
As I said you can use the Draw method. For stretching, there is also a StretchDraw method :
Code: [Select]
  ImageList1.Draw(Canvas,x,y,index);
  ImageList1.StretchDraw(Canvas,index,rect(0,20,100,120));
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018