Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-02

Bitmap transparency problem (I don't want transparency)

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Pierre Delore

Hi,

I have a transparency problem when I try to display a bitmap stored in a TImagList. The bitmap I want to display is a green arrow with a white background. I want to display it without transparency. With the code below the bitmap is displayed but the background is not white (it's a copy of a part of the screen). If I uncomment the 2 lines with the fillrect, the background is set to green.

Any ideas?

--------------------------------------------------------------------------------------------------------
procedure TImgList.Paint;
var
Bitmap: TBitmap;
begin
Bitmap := TBitmap.Create;
try
Bitmap.Height := pHeight;
Bitmap.Width := pWidth;
TImgListItem(ListImg.Items[index]).ImgList.GetBitmap(tagv,Bitmap); //the image is a green arrow with a white background
Bitmap.Transparent:=False;
//Canvas.Brush.Color := clGreen; If I uncomment this part the background is set to green
//Canvas.FillRect(0,0,pwidth,pheight);
Canvas.Draw(0, 0, Bitmap);
finally
Bitmap.Free;
end;
inherited Paint;
end;

Regards.

Reply by email

Howard Page-Clark
to Pierre Delore
Pierre Delore wrote 37 lines
Hi, I have a transparency problem when I try to display a bitmap stored in a TImagList. The bitmap I want to display is a green arrow with a white background. I want to display it without transparency. With the code below the bitmap is displayed but the background is not white (it's a copy of a part of the screen). If I uncomment the 2 lines with the fillrect, the background is set to green. Any ideas? >-------------------------------------------------------------------------------------------------------- procedure TImgList.Paint; var Bitmap: TBitmap; begin Bitmap := TBitmap.Create; try Bitmap.Height := pHeight; Bitmap.Width := pWidth; TImgListItem(ListImg.Items[index]).ImgList.GetBitmap(tagv,Bitmap); //the image is a green arrow with a white background Bitmap.Transparent:=False; //Canvas.Brush.Color := clGreen; If I uncomment this part the background is set to green //Canvas.FillRect(0,0,pwidth,pheight); Canvas.Draw(0, 0, Bitmap); finally Bitmap.Free; end; inherited Paint; end;

Difficult to be sure based on an uncompilable code snippet. Presumably TImgList is a TImage (not a TImageList)?
But you carefully create a bitmap and draw it on the component's canvas, and then draw over it again with a call to inherited Paint.

HTH

Howard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100221/a08d922d/attachment.html>

Reply by email

waldo kitty
to Pierre Delore: I have a transparency problem when I try to display a bitmap stored in a TImagList. The…
Pierre Delore wrote 11 lines
Hi, I have a transparency problem when I try to display a bitmap stored in a TImagList. The bitmap I want to display is a green arrow with a white background. I want to display it without transparency. With the code below the bitmap is displayed but the background is not white (it's a copy of a part of the screen). If I uncomment the 2 lines with the fillrect, the background is set to green. Any ideas?

one question that comes to my mind is if the actual image you are working with carries the attribute that color X is transparent... there are many times that i work with graphics and block out the entire background in some color that does not exist anywhere else in the graphic and then set it as the transparent color within the file... on some graphics, this may be a neon green or blue and in others it may be white or black... it all depends but the point i'm making is what the graphic contains and how those attributes may be being interpreted by the code you are using...

Reply by email

Peter Williams
to Pierre Delore: I have a transparency problem when I try to display a bitmap stored in a TImagList. The…

Hi Pierre and Lazarus list,

2010/2/22 Pierre Delore :

Show quoted text 9 lines
Hi, I have a transparency problem when I try to display a bitmap stored in a TImagList. The bitmap I want to display is a green arrow with a white background. I want to display it without transparency. With the code below the bitmap is displayed but the background is not white (it's a copy of a part of the screen). If I uncomment the 2 lines with the fillrect, the background is set to green.

I think that you commented code reveals why this is happening. See my untested suggested code
changes below.

Any ideas?

a--------------------------------------------------------------------------------------------------------

Show quoted text 16 lines
procedure TImgList.Paint; var ? Bitmap: TBitmap; begin ??? Bitmap := TBitmap.Create; ??? try ????? Bitmap.Height := pHeight; ????? Bitmap.Width := pWidth; ????? TImgListItem(ListImg.Items[index]).ImgList.GetBitmap(tagv,Bitmap); //the image is a green arrow with a white background ????? Bitmap.Transparent:=False; ????? //Canvas.Brush.Color := clGreen;???????? If I uncomment this part the background is set to green
// set colour of the Canvas Brush to white (using the constant "clWhite")
       Canvas.Brush.Color := clWhite;
????? //Canvas.FillRect(0,0,pwidth,pheight);
// now fill the background of the Canvas with the Canvas.Brush.Color
set to colour white
       Canvas.FillRect(0,0,pwidth,pheight);
// note that my changes (above) are proposed, untested to the code
which you posted.
// my modifications to your code *should* make the background of the
Canvas clWhite before you draw Bitmap -- with the next line of code.
????? Canvas.Draw(0, 0, Bitmap);
// hopefully now Bitmap will be drawn on a clWhite background... which
is the effect you said in your email you're wanting.
Show quoted text 23 lines
??? finally ????? Bitmap.Free; ??? end; ? inherited Paint; end; Regards. -- Pierre Delore http://datalinkwristapps.free.fr http://dpsite.free.fr -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

I hope that these mods to your posted code help. Please note that they are proposed and untested.

Note: in my comments I use the British spelling of the word "colour" not American spelling of "color".

With LOVE from PEW ;-)))

Fond Regards, Peter Eric (aka 'pew') WILLIAMS
from Hobart, Tasmania, Australia -- phone (03) 6236-9675

My free website is: http://pewtas.googlepages.com (or) http://tinyurl.com/yuyejs

(please visit my free website and let me know what you think about it.)

Reply by email