【发布时间】:2010-12-24 07:40:23
【问题描述】:
我有一个带有自己的 alpha 混合的 png 图像文件。现在我想将它加载到手机中的表单上。我尝试了很多方法,但没有奏效。有什么解决办法吗?提前致谢。 这是我用来从资源加载图像的:
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("drawObj.Graph.png");
Bitmap myPNGImg = new Bitmap(stream);
然后创建与图像 Graph.png 相同大小的新位图:
Bitmap myBlankImg = new Bitmap(48,48);
Graphics mynewGraph = Graphics.FromImage(myNew);
mynewGraph.Clear(Color.Transparent);
绘制PNG位图:mynewGraph.DrawImage(myPNGImg, 0, 0);
然后是我从网上读到的东西:(
Rectangle rectDest = new Rectangle(50,50, 100, 100);
ImageAttributes imgatt = new ImageAttributes();
imgatt.SetColorKey(Color.Transparent, Color.Transparent);
myGraph.DrawImage(myNew, rectDest, 0, 0, 99, 99,GraphicsUnit.Pixel, imgatt);
它有效,但只需清除图像的四个角(某种圆角矩形)。剩下的图像周围仍有一些白色边框。
【问题讨论】:
-
也许你可以发布一些代码......
-
由于我不熟悉 CF 及其图形限制,因此我将其添加为评论:带有 alpha 的 png 中不需要的“边缘”的通常来源是创建 png启用抗锯齿功能。 CodeProject 上有一篇文章深入探讨了这一点(在 WinForms 中使用 LayeredWindow [WS_EX_LAYERED] 的上下文中):codeproject.com/KB/miscctrl/AlphaForm.aspx
标签: c# compact-framework