Pergunta

Eu tenho um aplicativo .NET 2.0 que funciona muito bem em XP e Vista, mas no Windows 7 RC (x64) ele trava com o seguinte erro:

informações de exceção


Tipo de exceção: System.OutOfMemoryException Mensagem: Falta de memória. Dados: System.Collections.ListDictionaryInternal TargetSite: .ctor void (System.Drawing.Image, System.Drawing.Drawing2D.WrapMode) HelpLink: NULL Fonte: System.Drawing

Informações StackTrace


no System.Drawing.TextureBrush..ctor (imagem de imagem, WrapMode WrapMode) em System.Windows.Forms.ControlPaint.DrawBackgroundImage (Graphics g, Imagem backgroundImage, cores backColor, ImageLayout BackgroundImageLayout, limites Retângulo, Retângulo clipRect, Ponto scrollOffset, RightToLeft RightToLeft) em System.Windows.Forms.Control.PaintBackground (PaintEventArgs e, retângulo retângulo, backColor cores, Ponto scrollOffset) em System.Windows.Forms.Control.PaintBackground (PaintEventArgse, retangular rectângulo) em System.Windows.Forms.Control.OnPaintBackground (PaintEventArgse pevent) em System.Windows.Forms.ScrollableControl.OnPaintBackground (PaintEventArgse) em System.Windows.Forms.Control.PaintWithErrorHandling (PaintEventArgse, camada Int16, booleanas disposeEventArgs) em System.Windows.Forms.Control.WmPaint (Mensagem & m) em System.Windows.Forms.Control.WndProc (Mensagem & m) em System.Windows.Forms.ScrollableControl.WndProc (Message & m)

Todas as ideias sobre por que isso está acontecendo, ou como eu pode programar em torno dele? É só pintar um winform padrão com nenhum fundo especial.

UPDATE: Descobri que este é apenas um problema quando o BackgroundImageLayout = ImageLayout.Tile, que também é o padrão. Configurá-lo para Zoom ou Center, e os dissapears questão. Isso é muito embora insatisfatório, porque eu preciso dele para telha.

Foi útil?

Solução 2

Acontece que a solução para isso tinha a ver com o arquivo PNG em si usado para o fundo. Eu só abriu com Paint.NET e resaved-lo, em seguida, colocá-lo de volta no projeto e funcionou.

Não sei o que mudou, mas resolveu o problema.

Outras dicas

Eu tive um problema semelhante. No meu caso eu tinha eliminado meu MemoryStream Eu carreguei a imagem.

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

Por favor, não descarte a imagem ou fechar o objeto FileStream de onde você tem a imagem antes de chamar a classe TextureBrush para a telha. Caso contrário, a classe TextureBrush irá lançar uma exceção sem memória.

Assim, a melhor maneira é para mostrar a imagem em mosaico chamando o TextureBrush imagem e, em seguida, fechar o objeto filestream no evento Paint das janelas formar.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top