ASP.NET Gather information about an image

Posted on 2009-02-20
Medium Priority
Last Modified: 2012-05-06
Hello experts.

On my web site I have created the ability to upload, resize and store images.

I now want to be able to gather extra information about these images such as.

When the image was taken.
By what camera etc.

These images will be photographs taken by digital cameras so they will have this type of info embedded into the file.

So my question is how do I get access to this?

I am currently using the asp.net file upload control.

Question by:thomasmutton
  • 4
LVL 21

Expert Comment

ID: 23695213
Using a Bitmap or Image object, you must load the image first in the instance object....Then using either one of the before mentioned, it will have accessors ...i.e.  Bitmap x = (Path...filename);....
                                         int x = x.Width;
LVL 21

Expert Comment

ID: 23695223
if you look up the properties of image, bitmap/image will have an accessor for each property of the image...some may have null value, you have to take that into consideration....
LVL 21

Expert Comment

ID: 23695225
and finally, yes,  you have to load image...no way to just go into the directory and get attributes of file that way...

Author Comment

ID: 23695291
This is the code I have been using to resize the image..

So what you are saying is that I have to get the properties from the bitmap object?

So in my case it would be accessed at
Bitmap temp ?

I have looked at the properties of this bitmap object and there are none for exif data..
    private void ResizeImageWithAspect(int intWidth, string strSize)
        Image original = System.Drawing.Image.FromStream(new MemoryStream(byteImage));
        //Find the aspect ratio between the height and width.
        float aspect = (float)original.Height / (float)original.Width;
        //Calculate the new height using the aspect ratio
        // and the desired new width.
        int newHeight = (int)(intWidth * aspect);
        //Create a bitmap of the correct size.
        Bitmap temp = new Bitmap(intWidth, newHeight, original.PixelFormat);
        //Get a Graphics object from the bitmap.
        Graphics newImage = Graphics.FromImage(temp);
        int intFontWidth = 215;
        int intFontHeight = 35;
        int intFontSize = 10;
        // Create font
        System.Drawing.Font font = new System.Drawing.Font("Trebuchet MS", intFontSize);
        // Create text position
        System.Drawing.PointF point = new System.Drawing.PointF(temp.Width - intFontWidth, temp.Height - intFontHeight);
        //Draw the image with the new width/height
        newImage.DrawImage(original, 0, 0, intWidth, newHeight);
        if (strSize == "620")
            //Draw on the watermark
            newImage.DrawString("Copyright © " + DateTime.Now.Year.ToString() + " GowerUK.com", font, System.Drawing.Brushes.White, point);
        //Save the bitmap
        temp.Save(HttpContext.Current.Server.MapPath("~/Images/UserPhotos/" + strSize + "/" + intId.ToString() + ".jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
        //Dispose of our objects.

Open in new window

LVL 21

Accepted Solution

silemone earned 2000 total points
ID: 23695774
ok...i see what you mean...


they have  a library to use to do this...just add it to your bin and reference it...

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question