构建将部分透明图像像素变黑

发布于 2024-09-05 22:50:41 字数 685 浏览 3 评论 0原文

我对 C# 很陌生,遇到了一个问题但无法解决。我有一排分配有 .png 图像的按钮。图像采用 .png 格式以实现透明,并且在 GIMP 中平滑边缘会留下一些半透明像素。我已将图像列表工具栏 (imglToolbar) 的属性设置为将“透明”识别为指定颜色以显示为透明。我正在使用 Visual Studio 2005。

奇怪的是,当我查看 Visual C# 表单预览窗口时,一切看起来都很棒。这些图标看起来完全符合其应有的样子。然而,一旦我实际构建了项目,按钮就会将图像边缘附近的每个半透明像素视为黑色。看起来它无法处理既透明又有颜色的情况。

通过 Visual C# 表单编辑器获得的图像:

替代文本 http://img5.imageshack。 us/img5/2577/whatiwanted.jpg

构建后的图像:

替代文本 http://img690.imageshack.us/img690/7241/whatigot.jpg

关于为什么会发生这种情况有什么想法吗?

I'm very new to C# and I've run into a problem and haven't been able to solve it. I have a row of buttons that have .png images assigned to them. The images are in .png format to allow transparency, and smoothing the edges in GIMP leaves some semi-transparent pixels. I've set the Image List Toolbar (imglToolbar)'s properties to recognize "Transparent" as the designated color to show up as transparent. I'm working in Visual Studio 2005.

The strange thing is that everything looks great when I'm viewing the Visual C# form preview window. The icons look exactly as they should. However, once I actually build the project, the buttons treat every semi-transparent pixel near the edge of the image as if it's black. It seems like it can't handle one that's both transparent and has color.

Image of it via the Visual C# form editor:

alt text http://img5.imageshack.us/img5/2577/whatiwanted.jpg

Image of what it looks like when built:

alt text http://img690.imageshack.us/img690/7241/whatigot.jpg

Any ideas as to why this is happening?

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

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

发布评论

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

评论(2

深居我梦 2024-09-12 22:50:41

我刚刚找到了答案,至少针对我的具体情况。

我正在处理的表单是一个顶级 MDI 容器。无论出于何种原因,将图标设置为 32 位颜色都不允许正确解释这些半透明像素。一时兴起将其设置为24位,彻底解决了问题。不确定这是否是由于某些看不见的因素而出现的情况,但颜色深度的变化解决了我的问题。

另外,对于那些可能遇到类似问题的人,请确保该窗口不是 MDI 容器的子窗口。在查找信息时,我发现MDI子项根本不支持TransparencyKeys。

I just found the answer, at least to my specific situation.

The form I'm dealing with is a top-level MDI container. For whatever reason, having the icons set to 32 bit color doesn't allow for these semi-transparent pixels to be properly interpreted. Setting it to 24-bit, on a whim, completely solved the problem. Not sure if this is some situation that has come up as a result of some unseen factor, but the color depth change fixed my problem.

Also for those who may come here with a similar problem, make sure the window isn't a child of an MDI container. While looking for information, I found MDI children don't support TransparencyKeys at all.

冰之心 2024-09-12 22:50:41

我也遇到了这个问题;将表单的 IsMdiContainer 属性更改为 false 解决了这个问题。

I ran into this problem as well; changing the form's IsMdiContainer property to false solved it.

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