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)

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Pierre Delore

hi all,

Thanks for your answers.

I forgot to specify that I'm in Win32 with 0.9.28.2 (not a snapshot).

Peter, I uncommented the 2 lines and I replaced clGreen by clWhite. The image is displayed correctly. I changed the background of the image and I set it to blue (FF0000). The image is displayed correctly. I also replace the clWhite by clBlue. The image is displayed correctly.

Somebody can explain me why I had this problem?

Is there a visual component that allow to display an image from an imagelist (a TImage descendant for example)?

Regards

Pierre Delore http://datalinkwristapps.free.fr http://dpsite.free.fr ----- "Peter Williams" a ?crit : > Hi Pierre and Lazarus list, > > 2010/2/22 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. > > I think that you commented code reveals why this is happening. See my > untested suggested code > changes below. > > > > > Any ideas? > > > a-------------------------------------------------------------------------------------------------------- > > 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. > > > 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.) > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100222/bf3ee8d2/attachment.html>

Reply by email

Peter Williams
to Pierre Delore

Hi Pierre and Lazarus List

see my comments below...

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

2010/2/22 Pierre Delore :

Show quoted text 14 lines
hi all, Thanks for your answers. I forgot to specify that I'm in Win32 with 0.9.28.2 (not a snapshot). Peter, I uncommented the 2 lines and I replaced clGreen by clWhite. The image is displayed correctly. I changed the background of the image and I set it to blue (FF0000). The image is displayed correctly. I also replace the clWhite by clBlue. The image is displayed correctly. From Delphi graphical game I created, which I converted to Lazarus ...

some time ago,

( code from the attached file "uFixedWidthFonts.pas" )

const
  Rects_low = 0;
  Rects_high = 255;
type
  // these lines "borrowed" from SDL.pas
  SInt16 = smallint;
  UInt16 = word;
// [ALVAROGP] TSDL_Rect converted to class, to avoid warnings
  TSDL_Rect = class
  public
    x, y: SInt16;
    w, h: UInt16;
  end;
  // end lines from SDL
  PFixedFont = ^TFixedFont;
  TFixedFont = object
  private
    Image: TBitmap;
// [ALVAROGP] Rects redefined as array of class TSDL_Rect
    Rects: array[Rects_low..Rects_high] of TSDL_Rect;
//...
    TransparentColor : Tcolor;
//...
//code...
  // Determine the transparent color
  TransparentColor := Image.Canvas.Pixels[Rects[Rects_low].x +
    Rects[Rects_low].w, 0];

Note: the above line can be simplified as:

// this will return a TColor of the colour of the pixel @ location [0,0] of
// TBitmap e.g. the top left corner pixel of the image.
// You could choose ANY x,y pixel of the image to be the background colour.
TransparentColor := Image.Canvas.Pixels[0, 0];
// set colour of the Canvas Brush to TransparentColor
Canvas.Brush.Color := TransparentColor;
// now fill the background of the Canvas with the TransparentColor
      Canvas.FillRect(0,0,pwidth,pheight);
// my modifications to your code *should* make the background of the
// Canvas to the same colour as the TBitmap's colour at pixel [0,0]
// before you draw Bitmap -- with the next line of code.
Canvas.Draw(0, 0, Bitmap);
// or with my var declarations it would be:
  Canvas.Draw(0, 0, Image);
// hopefully now Bitmap will be drawn on a clWhite background... which
is the effect you said in your email you're wanting.
finally Bitmap.Free;
// or with my var declarations it would be:
         Image.Free
end; inherited Paint; end;
Somebody can explain me why I had this problem?

<snip>

Show quoted text 9 lines

<snip>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: uFixedWidthFonts.pas
Type: text/x-pascal
Size: 6282 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100222/eb3db41a/attachment.bin>

Reply by email

Pierre Delore

Thanks Peter for your example.
I'm understand your code but my first goal was to display an image (from an imagelist) without the transparency effect (that's why I set Transparent to false).

I didn't understand why if I set the transparent property to false the effect seem to be active.

Bug or (probably) something is missing in my code. A solution was found with the a 'fillrect' with a white brush. But is it normal?

Regards.

Pierre Delore http://datalinkwristapps.free.fr http://dpsite.free.fr Le 22/02/2010 11:37, Peter Williams a ?crit : > Hi Pierre and Lazarus List > > see my comments below... > > 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.) > > 2010/2/22 Pierre Delore: >> hi all, >> >> Thanks for your answers. >> >> I forgot to specify that I'm in Win32 with 0.9.28.2 (not a snapshot). >> >> Peter, I uncommented the 2 lines and I replaced clGreen by clWhite. The >> image is displayed correctly. >> I changed the background of the image and I set it to blue (FF0000). The >> image is displayed correctly. >> I also replace the clWhite by clBlue. The image is displayed correctly. >> > >> From Delphi graphical game I created, which I converted to Lazarus ... > some time ago, > > ( code from the attached file "uFixedWidthFonts.pas" ) > > const > Rects_low = 0; > Rects_high = 255; > > type > // these lines "borrowed" from SDL.pas > SInt16 = smallint; > UInt16 = word; > > // [ALVAROGP] TSDL_Rect converted to class, to avoid warnings > TSDL_Rect = class > public > x, y: SInt16; > w, h: UInt16; > end; > > // end lines from SDL > > PFixedFont = ^TFixedFont; > TFixedFont = object > private > Image: TBitmap; > // [ALVAROGP] Rects redefined as array of class TSDL_Rect > Rects: array[Rects_low..Rects_high] of TSDL_Rect; > //... > TransparentColor : Tcolor; > //... > > //code... > // Determine the transparent color > TransparentColor := Image.Canvas.Pixels[Rects[Rects_low].x + > Rects[Rects_low].w, 0]; > > Note: the above line can be simplified as: > > // this will return a TColor of the colour of the pixel @ location [0,0] of > // TBitmap e.g. the top left corner pixel of the image. > // You could choose ANY x,y pixel of the image to be the background colour. > > TransparentColor := Image.Canvas.Pixels[0, 0]; > > // set colour of the Canvas Brush to TransparentColor > Canvas.Brush.Color := TransparentColor; > > // now fill the background of the Canvas with the TransparentColor > Canvas.FillRect(0,0,pwidth,pheight); > > // my modifications to your code *should* make the background of the > // Canvas to the same colour as the TBitmap's colour at pixel [0,0] > // before you draw Bitmap -- with the next line of code. > >> Canvas.Draw(0, 0, Bitmap); > // or with my var declarations it would be: > Canvas.Draw(0, 0, Image); > > // hopefully now Bitmap will be drawn on a clWhite background... which > is the effect you said in your email you're wanting. > >> finally >> Bitmap.Free; > // or with my var declarations it would be: > Image.Free >> end; >> >> inherited Paint; >> end; > > >> Somebody can explain me why I had this problem? >> > <snip> >> >> Regards >> >> -- >> Pierre Delore >> >> http://datalinkwristapps.free.fr >> http://dpsite.free.fr >> > <snip> > > > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- Pierre Delore http://datalinkwristapps.free.fr -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100222/10e6dfb4/attachment.html>

Reply by email