This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Failed to save with Exif and IPTC data

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


	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);
        }
    }
Hi,

Here is a quote from Wikipedia:

Exif metadata are restricted in size to 64 kB in JPEG images because according to the specification, this information must be contained within a single JPEG APP1 segment. Although the FlashPix extensions allow information to span multiple JPEG APP2 segments, these extensions are not commonly used. This has prompted some camera manufacturers to develop non-standard techniques for storing the large preview images used by some digital cameras for LCD review. These non-standard extensions are commonly lost if a user re-saves the image using image editor software, possibly rendering the image incompatible with the original camera that created it. (In 2009, CIPA released the Multi Picture Object specification which addresses this deficiency and provides a standard way to store large previews in JPEG images.[13])


So, it seems that the size of metadata is over 64 kB, and you need to remove some fields to resave the image. Could you send us the file you would like to process? You can submit a case if it is more convenient for you.

Alternatively, we may consider storing of EXIF metadata in multiple JPEG APP segments. We did preliminary research of this task, and we need several work days to implement it.
We fixed this problem in the later version of Graphics Mill that you use ( 7.5.82.0). So, please consider upgrading to the last version, which is backward compatible.