Solved

How Do I Prevent the Loss of EXIF Data when RESAMPLING a file with C# System.Drawing?

Posted on 2013-05-11
3
649 Views
Last Modified: 2013-09-05
When images are resampled in ASP.NET they lose their Original Date of Capture and other important EXIF data such as Latitude and Longitude. The images will inevitably be encoded to reduce filesize as well so any solutions need to consider this also. The SetPropertyItem is the one of interest. Is it also possible to use this method to extract the EXIF data values without using specific EXIF HEX code methods. Below is my basic code prior to processing;
 using (Bitmap originalImage = new Bitmap(file.InputStream))
            {

                Bitmap bitmapImage = ResizeImage(RadUpload1.UploadedFiles[0].InputStream);        
                
                //bitmapImage.SetPropertyItem(bitmapImage.PropertyItems[0]);

                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                bitmapImage.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);

Open in new window

0
Comment
Question by:XGIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39159213
my solution for you would be to extracting the EXIT data before resampling the image and reset them again afterwards, since when loading the image to Bitmap u essentially losing the EXIT data.
check this code of extracting EXIT data from image:
http://www.codeproject.com/Articles/11305/EXIFextractor-library-to-extract-EXIF-information

here's a code usage:
            var imagefile = @"C:\Users\m.rivkin\Pictures\20130504_112103.jpg";
//extract all EXIF data before resizing image
            var props = EXIFextractor.GetExifProperties(imagefile);
            using (Bitmap originalImage = new Bitmap(imagefile))
            {
                Bitmap bmp = new Bitmap(originalImage.Width / 2, originalImage.Height / 2);
                
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.DrawImage(originalImage, 0, 0, originalImage.Width / 2, originalImage.Height / 2);
                }

//set EXIF data back to modified image
                foreach (var item in props)
                {
                    bmp.SetPropertyItem(item);
                }

                bmp.Save(@"c:\temp\1.jpg");
            }

Open in new window

0
 
LVL 7

Author Comment

by:XGIS
ID: 39166933
Thankyou for that i will check it out.  I did use a different exif class in a sample but it did not get lat longs. Hopefully this one will.
0
 
LVL 7

Author Comment

by:XGIS
ID: 39386154
I may need to supply a code sample to further this one, as my integration has not worked yet
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

737 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