Raymund#32880
Hi,
This question may similar to another topic "Problems when saving Exif and IPTC" in the forum, but even if I try to remove the thumbnail, I still get the following error:
EXIF data object is too big, its size exceeds 64K limit (that is defined by Jpeg standart for APP1 marker data)
Can you please provide more information about this?
BTW, Aurigma.GraphicsMill version is 7.5.82.0 and the image link is below:
Failed Image
This question may similar to another topic "Problems when saving Exif and IPTC" in the forum, but even if I try to remove the thumbnail, I still get the following error:
EXIF data object is too big, its size exceeds 64K limit (that is defined by Jpeg standart for APP1 marker data)
Can you please provide more information about this?
BTW, Aurigma.GraphicsMill version is 7.5.82.0 and the image link is below:
Failed Image
public class Program
{
public static void Main(string[] args)
{
var sourceImageData = File.ReadAllBytes("where_the_file_is");
using (MemoryStream ms = new MemoryStream(sourceImageData))
{
var metadatas = GetMetadata(ms);
var orgExif = metadatas.Item1;
var orgIptc = metadatas.Item2;
ms.Position = 0;
using (var rgbSourceStream = new MemoryStream())
{
using (var rawBitmap = new Aurigma.GraphicsMill.Bitmap(ms))
{
rawBitmap.ColorProfile = Aurigma.GraphicsMill.ColorProfile.FromSrgb();
if (rawBitmap.PixelFormat.IsCmyk || rawBitmap.PixelFormat.IsGrayscale)
{
rawBitmap.ColorManagement.Convert(Aurigma.GraphicsMill.ColorSpace.Rgb, true, rawBitmap.PixelFormat.IsExtended);
}
// save metadata back
JpegSettings encdr = new JpegSettings
{
Quality = 100,
IsProgressive = false
};
// update author and copyright, but not applicable for this case, you can ignore the commented code
//if (!is3rdParty)
//{
// orgExif[Aurigma.GraphicsMill.Codecs.ExifDictionary.Artist] = _author;
// orgExif[Aurigma.GraphicsMill.Codecs.ExifDictionary.Copyright] = string.Format(_copyRightFormat, DateTime.Now.Year);
//}
encdr.Exif = orgExif;
encdr.Iptc = orgIptc;
try
{
rawBitmap.Save(rgbSourceStream, encdr);
}
catch (JpegMarkerException ex)
{
if (ex.Message.IndexOf("64K limit") != -1
&& encdr.Exif != null && encdr.Exif[ExifDictionary.Thumbnail] != null)
{
encdr.Exif.Remove(ExifDictionary.Thumbnail);
rawBitmap.Save(rgbSourceStream, encdr); // throws exception "EXIF data object is too big, its size exceeds 64K limit (that is defined by Jpeg standart for APP1 marker data)"
}
else
{
throw;
}
}
}
// do something else for rgbSourceStream....
}
}
}
private static System.Tuple<ExifDictionary, IptcDictionary> GetMetadata(MemoryStream msInput)
{
ExifDictionary orgExif;
IptcDictionary orgIptc;
try
{
using (var jpegReader = new JpegReader(msInput))
{
orgExif = jpegReader.Exif ?? new ExifDictionary();
orgIptc = jpegReader.Iptc ?? new IptcDictionary();
}
}
catch
{
try
{
using (var tiffReader = new TiffReader(msInput))
{
orgExif = tiffReader.Exif ?? new ExifDictionary();
orgIptc = tiffReader.Iptc ?? new IptcDictionary();
}
}
catch
{
// this is not a jepg format or tiff format file. We cannot get the Exif and Iptc data
orgExif = new ExifDictionary();
orgIptc = new IptcDictionary();
}
}
return new System.Tuple<ExifDictionary, IptcDictionary>(orgExif, orgIptc);
}
}