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);
4
  • stackoverflow.com/questions/16162524/… check this. Commented Feb 21, 2017 at 6:38
  • Please give suggestion ASAP Commented Feb 21, 2017 at 6: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 Commented Feb 21, 2017 at 6:58
  • please try to see enter link description here Commented Feb 21, 2017 at 7:04

2 Answers 2

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.
Sign up to request clarification or add additional context in comments.

Comments

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#

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.