Delphi 2007 和 2010 在位图上绘图时的差异

发布于 2024-10-04 23:20:37 字数 805 浏览 14 评论 0原文

以下代码在 Delphi 2007 中按预期工作。它从图像列表中获取位图,在其上绘制一个红色 X,并将新位图添加到同一图像列表的末尾:

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

在 Delphi 2010 上,使用相同的代码,红色 X 变成透明 X。我需要添加/更改什么才能使其在 Delphi 2010 中按预期工作?谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心的位置 2024-10-11 23:20:38

我在使用 Delphi XE2 时遇到了同样的问题,并通过在 ImageList 编辑器中取消选中“使用带有 alpha 通道的 XP 样式图像”选项来修复该问题。如果您已选中该选项,只需取消选中它即可。

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.

茶色山野 2024-10-11 23:20:38

在再次将 DynBmp.TransParentColor 添加到图像列表之前,它可能是 clRed。也许透明模式不再是 tmFixed 了?根据您的发现尝试调试并修复您的代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文