【发布时间】:2013-08-22 13:19:21
【问题描述】:
我一直在使用此代码在图片框中显示图标。
Image FromIcon(Icon ico)
{
try
{
this.toolTip1.SetToolTip(pictureBox1, "The icon of the Executable");
return ico.ToBitmap();
}
catch (Exception e)
{
this.toolTip1.SetToolTip(pictureBox1, "Don't worry, it looks perfectly fine on the executable!");
MessageBox.Show(e.Message + "\r\n" + e.StackTrace);
Clipboard.SetText(e.Message + "\r\n" + e.StackTrace);
// Alternate method
return Bitmap.FromHicon(ico.Handle);
}
}
但是它显示了这个错误。
Requested range extends past the end of the array.
at System.Runtime.InteropServices.Marshal.CopyToNative(Object source, Int32 startIndex, IntPtr destination, Int32 length)
at System.Runtime.InteropServices.Marshal.Copy(Byte[] source, Int32 startIndex, IntPtr destination, Int32 length)
at System.Drawing.Icon.ToBitmap()
图标也以一种讨厌的方式显示,
这与我在应用程序中使用的图标相同。会出什么问题?
那个图标和另一个一样是 32 位的。
如果我使用另一个图标,它可以正常工作并且不会弹出错误。
【问题讨论】:
-
图像有多少位?不确定是否支持 >32 位(如果可能?)
-
@Sayse 我不知道该怎么说图片。如果你愿意,我会上传图标。
-
我认为可能需要它,否则,请尝试使用任何其他图标并查看是否正常
-
使用 Bitmap.FromHicon stackoverflow.com/questions/15782857/…
-
@MrFox 这是我正在使用的替代方法,但渲染效果不佳。
标签: c# winforms icons picturebox