private static byte[] FixExifData(byte[] originalJpegData) { using (JpegDecoder jpegDecoder = new JpegDecoder()) { using (ExifExtractor exifExtractor = new ExifExtractor()) { using (ExifBuilder exifBuilder = new ExifBuilder()) { using (new JpegEncoder()) { int outOffset; byte[] out1; JpegStatus exifData1 = jpegDecoder.GetExifData(out outOffset, out out1, originalJpegData); if (exifData1 == JpegStatus.WrongFormat) { return(originalJpegData); } IconConverter.ThrowExceptionIfJpegResultFail(exifData1); Exif out2; IconConverter.ThrowExceptionIfJpegResultFail(exifExtractor.Parse(out out2, out1)); out2.Thumbnail = (byte[])null; IconConverter.ThrowExceptionIfJpegResultFail(jpegDecoder.SetJpegData(originalJpegData)); Size dimension = jpegDecoder.GetDimension(); IconConverter.ThrowExceptionIfJpegResultFail(exifBuilder.SetExif(out2)); byte[] exifData2 = exifBuilder.GetExifData(dimension.Width, dimension.Height); byte[] numArray = new byte[originalJpegData.Length - out1.Length + exifData2.Length]; int num1 = 0; Array.Copy((Array)originalJpegData, (Array)numArray, outOffset); int destinationIndex1 = num1 + outOffset; Array.Copy((Array)exifData2, 0, (Array)numArray, destinationIndex1, exifData2.Length); int destinationIndex2 = destinationIndex1 + exifData2.Length; Array.Copy((Array)originalJpegData, outOffset + out1.Length, (Array)numArray, destinationIndex2, originalJpegData.Length - (outOffset + out1.Length)); int num2 = exifData2.Length - out1.Length; int index = outOffset - 8; int num3 = ((int)originalJpegData[index] << 8) + (int)originalJpegData[index + 1] + num2; numArray[index] = (byte)(num3 >> 8); numArray[index + 1] = (byte)num3; return(numArray); } } } } }