代码之家  ›  专栏  ›  技术社区  ›  JYelton Melchior Blausand

对image.save重复使用位图变量,gdi+错误

  •  1
  • JYelton Melchior Blausand  · 技术社区  · 14 年前

    我有一系列位图图像需要使用.NET(C)保存,但正遇到一般的gdi+错误。

    我试图重用可能是我的问题的同一个变量。

    例如:

    Bitmap pic = MethodThatReturnsBitmap();
    pic.Save(MyPath);
    
    pic = AnotherMethodThatReturnsBitmap();
    pic.Save(AnotherPath);
    

    我是否需要在每个变量之间引入唯一变量和/或处理 .Save() ?

    1 回复  |  直到 14 年前
        1
  •  3
  •   AJ.    14 年前

    .Dispose() using

    using(Bitmap pic = MethodThatReturnsBitmap())
    {
        pic.Save(Path);
    }
    using(Bitmap pic = AnotherMethodThatReturnsBitmap())
    {
        pic.Save(AnotherPath);
    }