Domanda

Ho un'app .NET 2.0 che funziona perfettamente su XP e Vista, ma su Windows 7 RC (x64) si arresta in modo anomalo con il seguente errore:

Informazioni sull'eccezione


Tipo di eccezione: System.OutOfMemoryException Messaggio: memoria esaurita. Dati: System.Collections.ListDictionaryInternal TargetSite: Void .ctor (System.Drawing.Image, System.Drawing.Drawing2D.WrapMode) HelpLink: NULL Fonte: System.Drawing

Informazioni StackTrace


su System.Drawing.TextureBrush..ctor (Immagine immagine, WrapMode wrapMode) su System.Windows.Forms.ControlPaint.DrawBackgroundImage (Grafica g, Sfondo immagineImmagine, Colore retroColore, Sfondo layout immagine ImageLayout, Limiti rettangolo, Clip rettangoloRetto, Scorrimento puntoOffset, RightToLeft rightToLeft) su System.Windows.Forms.Control.PaintBackground (PaintEventArgs e, rettangolo rettangolo, Color backColor, Point scrollOffset) at System.Windows.Forms.Control.PaintBackground (PaintEventArgs e, Rectangle rectangle) at System.Windows.Forms.Control.OnPaintBackground (PaintEventArgs pevent) at System.Windows.Forms.ScrollableControl.OnPaintBackground (PaintEventArgs e) at System.Windows.Forms.Control.PaintWithErrorHandling (PaintEventArgs e, layer Int16, Boolean disposeEventArgs) at System.Windows.Forms.Control.WmPaint (Message & amp; m) at System.Windows.Forms.Control.WndProc (Message & amp; m) at System.Windows.Forms.ScrollableControl.WndProc (Message & amp; m)

Qualche idea sul perché questo accada o su come potrei programmarlo? Sta solo dipingendo una winform standard senza sfondo speciale.

UPDATE: Ho scoperto che questo è solo un problema quando BackgroundImageLayout = ImageLayout.Tile, che è anche l'impostazione predefinita. Impostalo su Zoom o Centro e il problema scompare. È piuttosto insoddisfacente, perché ne ho bisogno per tessere.

È stato utile?

Soluzione 2

Si scopre che la soluzione ha a che fare con il file PNG stesso usato per lo sfondo. L'ho appena aperto con Paint.NET e l'ho salvato di nuovo, quindi lo ho rimesso nel progetto e ha funzionato.

Non sono sicuro di cosa sia cambiato, ma ha risolto il problema.

Altri suggerimenti

Ho avuto un problema simile. Nel mio caso avevo eliminato il mio MemoryStream da cui ho caricato l'immagine.

//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);

Per favore non gettare l'immagine o chiudere l'oggetto filestream da dove hai ottenuto l'immagine prima di chiamare la classe TextureBrush per la piastrellatura. Altrimenti la classe TextureBrush genererà un'eccezione di Memoria esaurita.

Quindi il modo migliore è mostrare l'immagine affiancata chiamando l'immagine TextureBrush e quindi chiudere l'oggetto filestream nell'evento Paint del modulo windows.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top