c# - bitmap save jpeg failled but png is ok because of the comments property -


question description:

when save bitmap jpeg file jpeg format mode, gdi exception thrown. when save png format mode, can saved successfully.

quick recreate:

  1. please save images .jpg file broswer. click here: incorrectimage, correctimage.(actually, in our application, request image on fly , save image jpeg.)

  2. using below code see exception:

    string newfile = @"d:\temp\newimage.jpg"; var newbitmap = image.fromfile(@"d:\temp\incorrectimage.jpg"); newbitmap.save(newfile,system.drawing.imaging.imageformat.jpeg);

what found:

after deep investigation, found out root of issue the comments property of orginal image. when delete the property value, error disappears. besides, after copy value of comments value of image notepad , paste back, image can saved new image upper code , size of image larger! enter image description here

so, guess comments property might includes sensitive or incorrect charector when saving jpeg file. guys can give our insights on comments?

thanks in advanced.

more try:

i try below code:

        //foreach (var item in newbitmap.propertyitems)         //{         //    if (item.id == 37510)         //    {         //        item.value = null;         //        item.len = 0;         //    }         //}         newbitmap.removepropertyitem(37510);         newbitmap.save(newfile, system.drawing.imaging.imageformat.jpeg); 

if remove property item, newimage can saved successfully. however, if set value null comment out codes, exception still thrown.

please me:

  1. why image size larger(orginal size 48k, after cut , paste it's 78k) when clear comments , paste same value back. possible bug?
  2. why image can saved after clear comments , paste same value back? clipboard filter invalid charactors?
  3. why image still cann't saved have set comments property value null? if remove property, can work, before try?

hope can me find out root of issue.

i have found out root of issue msdn http://social.msdn.microsoft.com/forums/en-us/83b24aa5-511f-47cd-856a-4fbbb5688ddf/bitmap-save-jpeg-failled-but-png-is-ok-because-of-the-comments-property

it appears original comment uses ascii encoding gdi+ auto converts unicode. comment large , converting unicode doubles size , exceeds maximum size of exif block (64 kbytes).


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -