0

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).

user3369592
  • 1,367
  • 5
  • 21
  • 43
  • Good question, but one you can answer for yourself. Time it both ways and go with the faster method. If there is one. – adv12 Feb 08 '16 at 22:12
  • If you are dealing with 100TB of photos use c++, since it is much more efficient. Also, you most likely don't have 100TB of memory, so good luck loading all those images into memory at the same time. – asdfasdfadsf Feb 08 '16 at 22:13
  • 1
    @JasonHeddle, there's nothing in the OP's question that indicates he plans to have all the images in memory at the same time. – adv12 Feb 08 '16 at 22:14
  • 1
    The Bitmap constructor always creates a Bitmap object, Image.FromFile() might too but can also return a Metafile. None of this has anything to do with speed. – Hans Passant Feb 08 '16 at 22:16
  • @adv12 I think I won't know which one will run faster unless I try both of them with 100TB data because I think it is possible that one method will run faster than another for the small amount of data but run much slower for the large amount of data. – user3369592 Feb 08 '16 at 22:18
  • @user3369592, that would be really weird. – adv12 Feb 08 '16 at 22:21
  • @HansPassant you might be right. Since both of them have "GetPropertyItem(int proid)" functions. – user3369592 Feb 08 '16 at 22:21
  • Looks like `Image.FromFile(...)` internally calls `Bitmap.FromGDIplus(...)` – Nyerguds Sep 06 '17 at 13:45

1 Answers1

1

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 bits per pixel (colour depth)?

...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

  • thank you for your comment. I need to read the image info and grab two image properties, image description and image date. Can I still use the solution you suggest? – user3369592 Feb 08 '16 at 22:42
  • Yes. These strategies will work for you, particularly EXIF, without requiring you to load the entire image file into memory. System.Drawing.Bitmap most likely depends on EXIF info to be present in the file for `GetPropertyItem()` to work –  Feb 08 '16 at 22:45
  • Thank you. What do you exactly mean " loading image headers", the header refers to the image info?? – user3369592 Feb 08 '16 at 22:49
  • It seems reading the image header can only get me the image dimension. Do you know how I can get the image properties and image date from reading the header? – user3369592 Feb 09 '16 at 19:53
  • @user3369592 Image properties is just an encapsualtion of image metadata such as that obtained from EXIF. Follow the links where EXIF is mentioned –  Feb 10 '16 at 00:08