Note that there are some explanatory texts on larger screens.

plurals
  1. PObitmap save jpeg failled but png is ok because of the comments property
    primarykey
    data
    text
    <p><strong>Question Description:</strong></p> <p>when I save the bitmap to a JPEG file with JPEG format mode, a Gdi exception was thrown. But when i save it with a PNG format mode, it can be saved successfully.</p> <p><strong>Quick Recreate:</strong></p> <ol> <li><p>Please save the images to .jpg file from the broswer. click here: <a href="http://www.screencast.com/t/JlMn7SRr" rel="nofollow noreferrer">IncorrectImage</a>, <a href="http://www.screencast.com/t/TVJvAQCp" rel="nofollow noreferrer">CorrectImage</a>.(actually, in our application, we request the image on the fly and then save the image to JPEG.)</p></li> <li><p>using the below code to see the exception:</p> <p><code>string newFile = @"D:\Temp\newImage.jpg"; var newBitmap = Image.FromFile(@"D:\Temp\IncorrectImage.jpg"); newBitmap.Save(newFile,System.Drawing.Imaging.ImageFormat.Jpeg);</code></p></li> </ol> <p><strong>What i found:</strong></p> <p>after a deep investigation, i found out the root of the issue is from <strong>the Comments property</strong> of the orginal image. when i delete the the property value, the error disappears. Besides, after i just copy the value of the comments value of the image to notepad and then paste back, the image can be saved into a new image with the upper code and the size of the image even is larger! <img src="https://i.stack.imgur.com/dzBd5.png" alt="enter image description here"></p> <p>So, i guess the comments property might includes some sensitive or incorrect charector when saving to a jpeg file. Would guys can give our some insights on those comments? </p> <p>thanks in advanced.</p> <p><strong>More try:</strong></p> <p>I try the below code:</p> <pre><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); </code></pre> <p>if I remove the property item, then the newimage can be saved successfully. However, if I just set its value null like the comment out codes, the exception is still thrown.</p> <p><strong>Please help me:</strong></p> <ol> <li>Why the image size is larger(orginal size is 48k, after cut and paste back it's about 78k) when I just clear the comments and then paste the same value back. Is it possible a bug?</li> <li>Why the image can be saved successfully after I clear the comments and then paste the same value back? is it the Clipboard filter some invalid charactors?</li> <li>Why the image still cann't be saved even I have set the comments property value is null? but if I remove the property, it can work, like the before i try?</li> </ol> <p>Hope you can help me find out the root of the issue. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload