Link to home
Start Free TrialLog in
Avatar of thomasmutton
thomasmuttonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP.NET Gather information about an image

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.

Thanks!
Avatar of silemone
silemone
Flag of United States of America image

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;
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....
and finally, yes,  you have to load image...no way to just go into the directory and get attributes of file that way...
Avatar of thomasmutton

ASKER

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.
        original.Dispose();
        temp.Dispose();
        newImage.Dispose();
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of silemone
silemone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial