سؤال

ولدي التطبيق. NET 2.0 الذي يعمل على ما يرام على XP وفيستا، ولكن على ويندوز 7 RC (x64) و تعطل بسبب الخطأ التالي:

ومعلومات استثناء


ونوع الاستثناء: System.OutOfMemoryException رسالة: خارج الذاكرة. بيانات: System.Collections.ListDictionaryInternal TargetSite: .ctor الفراغ (System.Drawing.Image، System.Drawing.Drawing2D.WrapMode) HELPLINK: NULL المصدر: System.Drawing

ومعلومات تتبع مكدس الذاكرة المؤقتة


وفي System.Drawing.TextureBrush..ctor (صورة صورة، WrapMode wrapMode) في System.Windows.Forms.ControlPaint.DrawBackgroundImage (الرسومات ز، صورة backgroundImage، اللون BACKCOLOR، ImageLayout backgroundImageLayout، حدود مستطيل، مستطيل خيار clipRect، نقطة scrollOffset، RightToLeft rightToLeft) في System.Windows.Forms.Control.PaintBackground (PaintEventArgs ه، مستطيل مستطيل، اللون BACKCOLOR، نقطة scrollOffset) في System.Windows.Forms.Control.PaintBackground (PaintEventArgs ه، مستطيل مستطيل) في System.Windows.Forms.Control.OnPaintBackground (PaintEventArgs pevent) في System.Windows.Forms.ScrollableControl.OnPaintBackground (PaintEventArgs ه) في System.Windows.Forms.Control.PaintWithErrorHandling (PaintEventArgs الإلكترونية، Int16 طبقة، منطقية disposeEventArgs) في System.Windows.Forms.Control.WmPaint (رسالة وم) في System.Windows.Forms.Control.WndProc (رسالة وم) في System.Windows.Forms.ScrollableControl.WndProc (رسالة وم)

وأي أفكار حول لماذا يحدث هذا، أو كيف يمكن البرنامج من حوله؟ انها مجرد رسم winform القياسية مع أي خلفية خاصة.

وUPDATE: لقد وجدت أن هذا هو مجرد المشكلة عند BackgroundImageLayout = ImageLayout.Tile، الذي هو أيضا الافتراضي. تعيين لتكبير أو مركز، ويختفي القضية. هذا غير مرضية جدا على الرغم من، لأنني في حاجة إليها لبلاط.

هل كانت مفيدة؟

المحلول 2

وتبين الحل لهذا كان علي القيام به مع ملف PNG نفسها المستخدمة في الخلفية. أنا فقط فتحه مع Paint.NET وresaved ذلك، ثم وضعها مرة أخرى في المشروع وأنه يعمل.

ولست متأكدا ما تغير، ولكن حل المشكلة.

نصائح أخرى

وكان لي مشكلة مماثلة. في حالتي أنا تخلصت من بلدي MemoryStream I تحميل الصورة من.

//The following throws and OutOfMemoryException at the TextureBrush.ctor():

    /*someBytes and g declared somewhere up here*/
    Bitmap myBmp = null;
    using(MemoryStream ms = new MemoryStream(someBytes))
       myBmp = new Bitmap(ms);

    if(myBmp != null) //that's right it's not null.
       using(TextureBrush tb = new TextureBrush(myBmp)) //OutOfMemoryException thrown
          g.FillRectangle(tb,0,0,50,50);

//This code does not throw the same error:

    /*someBytes and g declared somewhere up here*/
        MemoryStream ms = new MemoryStream(someBytes);
        Bitmap myBmp = new Bitmap(ms);

        if(myBmp != null)
           using(TextureBrush tb = new TextureBrush(myBmp))
              g.FillRectangle(tb,0,0,50,50);

يرجى عدم التخلص من صورة أو إغلاق الكائن FILESTREAM من حيث كنت قد حصلت على صورة قبل استدعاء الطبقة TextureBrush للبلاط. وإلا فإن الطبقة TextureBrush سوف بطرح خارج الاستثناء الذاكرة.

وهكذا هو أفضل وسيلة لإظهار الصورة تجانب عن طريق استدعاء TextureBrush صورة ثم قم بإغلاق الكائن FILESTREAM في حال الطلاء من شكل النوافذ.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top