打开一个由图片转换成的二进制文件,转成png格式,在画这些图片时会报内存不足。问:为什么会报内存不足?怎么解决?

解决方案 »

  1.   


    PointF[] destinationPoints = { new PointF(_dx + _dw, _dy), new PointF(_dx, _dy), new PointF(_dx + _dw, _dy + _dh) };
    g.DrawImage(_img, destinationPoints, _sr, GraphicsUnit.Pixel, imageAttributes);由于代码太乱了~~只粘了画的函数,这个_img不是空,当我把这个_img保存为png格式后,再用Image.FromFile(path);打开时,就不会报内存不足.图也是对的.
      

  2.   

    FileStream  MemoryStream  没关闭。把代码贴出来。
      

  3.   

    当我把这个_img保存为png格式后,再用Image.FromFile(path);打开时,就不会报内存不足.图也是对的.
      

  4.   

    打开之前把前面的画图片什么的都关闭就好了
      g.Dispose();
      stream.Close();
      

  5.   


    _img.Save(@"d:\0.png");
    Image img = Image.FromFile(@"d:\0.png");
    PointF[] destinationPoints = { new PointF(_dx + _dw, _dy),
     new PointF(_dx, _dy),
     new PointF(_dx + _dw, _dy + _dh) };
    g.DrawImage(_img, destinationPoints, _sr, GraphicsUnit.Pixel, imageAttributes);这样写就不会报内存不足,为什么会这样呢?
      

  6.   

     上面写错了~~_img 应该是img
      

  7.   


    “野指针” 能给点解释吗?我也觉得是对象赋值的问题,可是我用了图片的CLONE还是不行,复制BYTE[]不知道行不行?
      

  8.   

    //b = Image.FromFile("C:\\13.png");            //MemoryStream ms = new MemoryStream();            //b.Save(ms, ImageFormat.Png);            //byte[] bytes = ms.GetBuffer();            //FileStream fs = new FileStream(@"E:\1231.bit", FileMode.Create, FileAccess.Write);            //BinaryWriter bw = new BinaryWriter(fs);            //bw.Write(bytes.Length);            //bw.Write(bytes);            //bw.Close();            //fs.Close();            FileStream fs1 = new FileStream(@"E:\1231.bit", FileMode.Open, FileAccess.Read);            BinaryReader br = new BinaryReader(fs1);            int count = br.ReadInt32();            byte[] bytesArray = br.ReadBytes(count);            MemoryStream ms1 = new MemoryStream(bytesArray);            b1 = Image.FromStream(ms1);            br.Close();            fs1.Close();这样可以画b1,我伤不起啊~~~
      

  9.   

    GDI+在绘图时做了优化,从流打开的图片并不会立即全部读入内存中。如果绘制图片有缩略,可以只读取部分数据。
      

  10.   

    感谢大牛们的金玉良言,虽没有答案,却对GDI+,IO懂了多了一些。分不多,平均分了~~