2009-04-30 20 views
5

Ho un'applicazione .NET 2.0 che funziona bene su XP e Vista, ma su Windows 7 RC (x64) si blocca con il seguente errore:Windows 7 TextureBrush..ctor) Errore (

Eccezione Informazioni


Tipo di eccezione: System.OutOfMemoryException Messaggio: Memoria insufficiente. dati: System.Collections.ListDictionaryInternal TargetSite: .ctor Void (System.Drawing.Image, System.Drawing.Drawing2D.WrapMode) HelpLink: NULL Fonte: System.Drawing

StackTrace Informazioni


a System.Drawing.TextureBrush..ctor (Immagine immagine, WrapMode wrapMode) a System.Windows.Forms.ControlPaint.DrawBackgroundImage (Grafica g, Immagine backgroundImmagine, Colore backColor, ImmagineLayout backgroundImageLayout, Rettangolo, Rettangolo clipRetto, Punto scrollOffset , RightToLeft rightToLeft) in System.Windows.Forms.Control.PaintBackground (PaintEventArgs e, Rettangolo rettangolo, Colore backColor, Point scrollOffset) in System.Windows.Forms.Control.PaintBackground (PaintEventArgs e, Rectangle rectangle) in System.Windows.Forms. Control.OnPaintBackground (PaintEventArgs pevent) a System.Windows.Forms.ScrollableControl.OnPaintBackground (PaintEventArgs e) a System.Windows.Forms.Control.PaintWithErrorHandling (PaintEventArgs e, strato di Int16, booleane disposeEventArgs) a System.Windows.Forms .Control.WmPaint (Messaggio & m) a System.Windows.Forms.Control.WndProc (Messaggio & m) a System.Windows.Forms.ScrollableControl.WndProc (Messaggio & m)

Qualche idea sul perché questo sta accadendo o su come potrei programmare intorno ad esso? Dipinge semplicemente una winform standard senza uno sfondo speciale.

UPDATE: Ho riscontrato che questo è solo un problema quando BackgroundImageLayout = ImageLayout.Tile, che è anche l'impostazione predefinita. Impostalo su Zoom o Centro e il problema scompare. Questo è abbastanza insoddisfacente, perché ho bisogno di tessere.

+0

Funziona bene su XP e Vista ** 64-bit **? –

+0

Sì, funziona bene su entrambe le versioni a 32 e 64 bit di XP e Vista. –

+0

Grazie (è stato uno scatto al buio, ha avuto alcuni problemi di suono simili relativi a problemi cross-arch recentemente.) Scusa, per le idee. –

risposta

1

Risulta che la soluzione a questo ha a che fare con il file PNG utilizzato per lo sfondo. L'ho appena aperto con Paint.NET e l'ho ripassato, poi lo ho rimesso nel progetto e ha funzionato.

Non so cosa sia cambiato, ma ha risolto il problema.

+0

questo ha risolto il mio problema .. thnx –

3

Ho avuto un problema simile. Nel mio caso ho 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); 
+0

Questo era esattamente il mio problema. Qualcuno che capisce .net "sotto il cofano" si preoccupa di spiegare questo comportamento? – Dinei

1

Si prega di non smaltire l'immagine o chiudere l'oggetto FileStream da dove avete ottenuto l'immagine prima di chiamare la classe TextureBrush per il rivestimento. In caso contrario, la classe TextureBrush genererà un'eccezione di memoria insufficiente.

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