Solved

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

Posted on 2013-05-11
3
602 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now