Solved

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

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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 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