thomasmutton
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!
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!
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...
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..
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();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
int x = x.Width;