user3369592 February 2016

difference between image bitmap and fromFile methods in c#

I found out that there are two ways to read the image info using default c# library. One of them is

 System.Drawing.Image image = new Bitmap("file..path");

Another one is :

Image image = Image.FromFile("file..path");

May anyone tell me which one will run faster if I need to read a lot of images(nearly 100TB data).

Answers


MickyD February 2016

I found out that there are two ways to read the image info

You know, if it is just the image info you are after then I wouldn't use either function as both load the entire image into memory from disk - a rather wasteful exercise of the computer's resources.

Instead you should just load the image file header whether it be EXIF; BITMAPINFOHEADER or other depending on the image format. There are ways to load such info via .NET (see links below).

Image headers

Apart from RAW image file formats (not necessarily that which is output from SLR cameras), most image file formats have a header that can be loaded prior to loading the image raster data into memory from disk. In fact it is a generally a requirement that the header is read first because otherwise you would not know how much memory to allocate prior to loading the image.

  • How wide is it?
  • How tall?
  • How many colours per pixel?

...and so forth. These are all answered by reading the image file header first. As the name suggests, information about the image is generally near the start of the file. Exact formats and layout depends on the file format in question. See BMP; PNG resources for more info.

Here's some suggestions on loading image headers

Post Status

Asked in February 2016
Viewed 1,346 times
Voted 14
Answered 1 times

Search




Leave an answer