如何在 C# 中将具有透明部分的图像绘制到 Graphics 对象?

发布于 2024-09-30 12:18:15 字数 398 浏览 0 评论 0原文

我有一个正在绘制并显示的 Graphics 对象。这工作正常。不起作用的是绘制带有透明部分的 .png 图像。我正在通过调用从 ImageList 控件(如果有任何区别)绘制这些图像:

myGraphicsObject.DrawImage(myImage, x_position, y_position);

我没有专门为 .png 图像设置任何透明颜色值,并且在我的控件中找不到为 .png 图像指定透明颜色的任何值控制。

对于图像本身,我尝试在所需的透明部分填充 32 位 (255,0,255)、8 位 (0,0,0) 和白色 (255,255,255) 的透明颜色。不过,绘制时没有一个是不透明的。

有没有一种方法可以告诉图像对于指定的颜色变得透明?还有其他建议/解决方案吗?

I have a Graphics object that I am drawing to and displaying. This is working fine. The thing that is not working is drawing a .png image with a transparent section. I am drawing these images from am ImageList control (if that makes any difference) with the call:

myGraphicsObject.DrawImage(myImage, x_position, y_position);

I have not specifically set any transparent color value for the .png image and I cannot find any value in my control that specifies a transparent color for the control.

For the image itself I have tried filling the transparent colors for 32bit (255,0,255), 8bit (0,0,0), and white (255,255,255) in the desired transparent sections. None are not transparent when drawn, though.

Is there a method somewhere that tells the image to become transparent for a specified color? Any other suggestions/solutions?

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

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

发布评论

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

评论(2

一杆小烟枪 2024-10-07 12:18:15

该值位于表单本身上,而不是控件上,它称为 TransparencyKey 将其设置为您希望在 winforms 设计器中透明的颜色,以及等于该颜色的任何颜色(在您的仅表单)将不会被渲染。

The value is on the form itself, not the conrols, it is called TransparencyKey Set that to the color you wish to be transparent in the winforms designer, and any color that is equal to that color (in your form only) will be not be rendered.

心房的律动 2024-10-07 12:18:15

您的 PNG 是否在 ImageList 上正确显示(具有透明度)?也许您的 ImageList 设置为 24 位 RGB?更改为 32 位应该会有所帮助。

Does your PNG's display correctly (with transparency) on a ImageList? Maybe your ImageList is set to 24bit RGB? Change to 32bit and that should help.

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