1

When we upload a video and click into button to convert video into thumbnail image using this code it generate an error 'System.OutOfMemoryException: Out of memory.'

We are using this code

fpUplaodVideo.SaveAs(Server.MapPath("~/UploadFiles/SiteUserID_" + SiteUserID + "/UploadVideo/" + fpUplaodVideo.FileName));

error will occur on this line

System.Drawing.Image img1 = System.Drawing.Image.FromFile(Server.MapPath("~/UploadFiles/SiteUserID_" + SiteUserID + "/UploadVideo/") + fpUplaodVideo.FileName);
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
  • http://stackoverflow.com/questions/16162524/how-to-increase-memory-and-cache-size-for-application-pool-in-iis-7-efficiently check this. – Vijay Feb 21 '17 at 06:38
  • Please give suggestion ASAP – user3655990 Feb 21 '17 at 06:52
  • Your conversion to a thumbnail image is a bit simplistic, you cannot load a video by simply opening as if it was an image, you will have to do a bit more effort there. Also, asking for an "ASAP" suggestion seems a bit pushy, AKN has the correct answer which explains why you get the error, for converting the video to a thumbnail, I think you will need to do a bit more work – Icepickle Feb 21 '17 at 06:58
  • please try to see [enter link description here](http://stackoverflow.com/questions/15702031/get-thumbnail-image-of-video-file-in-c-sharp) – AKN Feb 21 '17 at 07:04

2 Answers2

4

System.Drawing.Image.FromFile will return OutOfMemoryException for below reason

  1. The file does not have a valid image format.
  2. GDI+ does not support the pixel format of the file.
AKN
  • 416
  • 2
  • 5
1

The MSDN documentation for Image.FromFile says this:

OutOfMemoryException

The file does not have a valid image format.

-or-

GDI+ does not support the pixel format of the file.

Granted, this is a bad and nonsensical use of the OutOfMemoryException, but at least it's documented.

As to why this is thrown, it's quite simple - you're trying to load a video file as an image file. The same docs show that the following formats are supported:

  • BMP
  • GIF
  • JPEG
  • PNG
  • TIFF

I assume your "UploadVideo" is none of these. In fact, I'm not sure why you assumed that this would produce a thumbnail image. Try looking for a specific library for that. This might be a good start: Thumbnail video C#

Community
  • 1
  • 1
Avner Shahar-Kashtan
  • 14,492
  • 3
  • 37
  • 63