gpt4 book ai didi

c# - 使用我的资源图像 - Compact Framework

转载 作者:行者123 更新时间:2023-11-30 17:07:49 26 4
gpt4 key购买 nike

我将图像添加到我的项目资源 (Windows Mobile 6.1)。我想使用此图像来设置我在表单中拥有的某些 PictureBoxes 的 PictureBox.Image 属性。我尝试以下代码:

pictureBox1.Image = Properties.Resources.my_image;
pictureBox2.Image = Properties.Resources.my_image;
pictureBox3.Image = Properties.Resources.my_image;

...

pictureBoxN.Image = Properties.Resources.my_image;

问题是有时图像只显示在某些 PictureBox 中(当我尝试设置图像时出现 TargetInvocationException),而不是全部显示。为什么?我该如何解决这个问题?

编辑:

InnerException 的 StackTrace:

in Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar) in System.Drawing.Bitmap._InitFromMemoryStream(MemoryStream mstream) in System.Drawing.Bitmap..ctor(Stream stream) in System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark) in System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) in System.Reflection.ConstructorInfo.Invoke(Object[] parameters) in System.Resources.ResourceReader.CreateResource(Type objType, Type[] ctorParamTypes, Object[] ctorParameters) in System.Resources.ResourceReader.LoadBitmap(Int32 typeIndex) in System.Resources.ResourceReader.LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode) in System.Resources.ResourceReader.LoadObject(Int32 pos, ResourceTypeCode& typeCode) in System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase) in System.Resources.ResourceManager.GetObject(String name, CultureInfo culture) in Icons_Control.Properties.Resources.get_glass_empty() in Icons_Control.ListItem.set_CompletitionStatus(eCompletionStatus value) in Icons_Control.ListItem..ctor() in Icons_Control.ListItem..ctor(eItemType type) in Icons_Control.MainForm.menuItem3_Click(Object sender, EventArgs e) in System.Windows.Forms.MenuItem.OnClick(EventArgs e) in System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam) in System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam) in System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam) in Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain) in System.Windows.Forms.Application.Run(Form fm) in Icons_Control.Program.Main()

最佳答案

我的猜测是您的内存或其他资源不足。图片资源有点危险。每次获得资源时,都会创建一个新资源。您可能只想创建一个 my_image 实例,并且可能希望在使用完它后将其丢弃。

Image myImage = Properties.Resources.my_image;

pictureBox1.Image = myImage;
pictureBox2.Image = myImage;
pictureBox3.Image = myImage;
pictureBox4.Image = myImage;
...
pictureBoxN.Image = myImage;

// Later on when you are done using it
myImage.Dispose();

对于大多数 CF 应用来说,不要浪费内存非常重要。

关于c# - 使用我的资源图像 - Compact Framework,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14256486/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com