我有一个图像上传器和裁剪器,它创建缩略图,我偶尔会在以下行中获得Out Of Memory异常:
Dim bm As Bitmap = System.Drawing.Image.FromFile(imageFile)
Run Code Online (Sandbox Code Playgroud)
错误的发生是微小的,非常罕见,但我总是想知道可能导致它的原因.imageFile变量只是一个Server.MapPath到图像的路径.
我很好奇,如果有人以前遇到过这个问题,他们是否有任何想法可能导致它?这可能是图像的大小吗?
我可以在必要时发布代码以及我所拥有的任何支持信息,但是我很乐意听到人们对此的看法.
@functions{
public void GetThumbnailView(string originalImagePath, int height, int width)
{
//Consider Image is stored at path like "ProductImage\\Product1.jpg"
//Now we have created one another folder ProductThumbnail to store thumbnail image of product.
//So let name of image be same, just change the FolderName while storing image.
string thumbnailImagePath = originalImagePath;
originalImagePath = originalImagePath.Replace("thumb_", "");
//If thumbnail Image is not available, generate it.
if (!System.IO.File.Exists(Server.MapPath(thumbnailImagePath)))
{
System.Drawing.Image imThumbnailImage;
System.Drawing.Image OriginalImage = System.Drawing.Image.FromFile(Server.MapPath(originalImagePath));
double originalWidth = OriginalImage.Width;
double originalHeight = OriginalImage.Height;
double …Run Code Online (Sandbox Code Playgroud) 我正在运行以下代码,以便在用户向我们发送图像时创建缩略图:
public int AddThumbnail(byte[] originalImage, File parentFile)
{
File tnFile = null;
try
{
System.Drawing.Image image;
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(originalImage))
{
image = System.Drawing.Image.FromStream(memoryStream);
}
Log.Write("Original image width of [" + image.Width.ToString() + "] and height of [" + image.Height.ToString() + "]");
//dimensions need to be changeable
double factor = (double)m_thumbnailWidth / (double)image.Width;
int thHeight = (int)(image.Height * factor);
byte[] tnData = null;
Log.Write("Thumbnail width of [" + m_thumbnailWidth.ToString() + "] and height of [" + thHeight + …Run Code Online (Sandbox Code Playgroud)