[英]Image.FromStream OutOfMemory Exception
I'm trying to get image from MemoryStream. 我正在尝试从MemoryStream获取图像。 When in MemoryStream I have a big JPG image (which size increases from 38MB to over 1.3GB after converting to bitmap in step commented as problematic) I get an OutOfMemory exception.
在MemoryStream中,当我有一个很大的JPG图像(在步骤中注释为有问题的步骤转换为位图后,其大小从38MB增加到1.3GB以上),我收到了OutOfMemory异常。 With smaller images everything works fine.
使用较小的图像,一切正常。 How to handle such problem?
如何处理这样的问题? Acceptable solution for me is to resize/rescale image stored in
_imgArray
below 1.3GB. 对我来说,可接受的解决方案是将存储在
_imgArray
中的图像调整为1.3GB以下。 Is it possible to do this before invoking Image.FromStream
method? 可以在调用
Image.FromStream
方法之前执行此操作吗?
public static Image GetImageFromByteArray(byte[] _imgArray)
{
Image imgFromArray = null;
MemoryStream stream = null;
try
{
stream = new MemoryStream(_imgArray, 0, _imgArray.Length);
imgFromArray = Image.FromStream(stream, true);//this line throws an Out of memory exception
}
catch(OutOfMemoryException)
{
Error.Warning("Das Bild ist zu groß!");
}
catch (Exception ex)
{
throw new FacadeException("Fehler beim Laden des Bildes.", ex);
}
finally
{
if (stream != null)
{
stream.Close();
}
}
return imgFromArray;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.