Link to home
Start Free TrialLog in
Avatar of XGIS
XGISFlag for Australia

asked on

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

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

ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of XGIS

ASKER

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.
Avatar of XGIS

ASKER

I may need to supply a code sample to further this one, as my integration has not worked yet