Mick
Mick

Reputation: 856

Difference between Delphi 2007 and 2010 when drawing on bitmaps

The following code works as expected with Delphi 2007. It takes a bitmap from an image list, draws a red X over it, and adds the new bitmap to the end of the same image list:

  DynBmp:=Graphics.TBitMap.Create;
  DynBmp.Transparent:=TRUE;
  DynBmp.TransparentMode:=tmFixed;
  ImgList.GetBitmap(9, DynBmp);
  DynBmp.TransparentColor:=DynBmp.canvas.pixels[0, DynBmp.Height - 1];
  DynBmp.Canvas.MoveTo(1, 1);
  DynBmp.Canvas.Pen.Style:=psAlternate; //psSolid;
  DynBmp.Canvas.Pen.Color:=clRed;
  DynBmp.Canvas.Pen.Width:=2;
  DynBmp.Canvas.LineTo(DynBmp.Width - 1, DynBmp.Height - 1);
  DynBmp.Canvas.MoveTo(DynBmp.Width - 1, 1);
  DynBmp.Canvas.LineTo(1, DynBmp.Height - 1);
  FErrBmpIdx:=ImgList.AddMasked(DynBmp, DynBmp.TransParentColor);
  aResetIcon.ImageIndex:=FErrBmpIdx;
  FreeAndNil(DynBmp);

On Delphi 2010, using the same code, the red X becomes a transparent X. What do I need to add/change to get it working as expected with Delphi 2010? Thanks

Upvotes: 1

Views: 721

Answers (2)

Faisal Azahrani
Faisal Azahrani

Reputation: 123

I had faced the same problem with Delphi XE2 and had fixed it by unchecking the "Use XP style image with alpha channel" option in ImageList Editor. If you had checked that option just uncheck it.

Upvotes: 2

Lars Truijens
Lars Truijens

Reputation: 43602

DynBmp.TransParentColor is probably clRed before you add it to the imagelist again. Maybe TransparentMode is not tmFixed anymore? Try debugging and fix your code according to your findings.

Upvotes: 0

Related Questions