我在C#
中使用了簡單的Image.RotateFlip()
方法,但我不斷收到一條錯誤,指出「內存不足」。我運行它通過一個分析器,發現它發生在System.Drawing.Image.FromFile();圖像旋轉內存錯誤
這裏是我的代碼:
protected void rotatePic(object sender, EventArgs e)
{
ImageButton img = sender as ImageButton;
string url = img.ImageUrl.Split('?')[0];
System.Drawing.Image pic = System.Drawing.Image.FromFile(Server.MapPath(url));
pic.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
pic.Save(Server.MapPath(url));
pic.Dispose();
img.ImageUrl = img.ImageUrl + "?" + DateTime.Now.ToString();
}
圖像有多大? – Quibblesome 2013-02-22 23:31:26
@Quibblesome他們總是不同,但最大的是4MB以下。 – 2013-02-22 23:34:01
很可能OOM是真實的。那就是你正在運行OOM,特別是如果Ed S是正確的,而且你沒有正確處理圖像。找出(如果它在代碼中不明顯)的最好方法是附加.NET內存分析器並檢查堆。雖然我在System.Drawing中遇到過不正確的OOM,但它們通常位於具有定製性差的操作系統的移動設備上。因此,在認爲API可能不合適之前,先對其進行配置並三重檢查您的代碼。 – Quibblesome 2013-02-22 23:36:18