Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2013-05-11
3
Medium Priority
?
746 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:
Meir Rivkin earned 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

810 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