Possible duplicate:
How can I get the best image compression results?
I am trying to create a 200 x 200px thumbnail using the following code. It works great for certain images, but not for others. When this does not work, a thumbnail is created with this size, but only a partial image is visible, and the other part is gray (for example, you used a gray brush and smeared it on top of the thumbnail). I could not see the trend when it fails. For example, it is not suitable for JPEG images with a size of 400px x 400px. If I try to create a sketch with a size of 150px x 150px, there is no image loss. If this helps here - this is one image that causes problems - http://s11.postimage.org/sse5zhpqr/Drawing_8.jpg
Rate your time.
public Bitmap GenerateThumbnail(Bitmap sourceBitmap, int thumbnailWidth, int thumbnailHeight) { Bitmap thumbnailBitmap = null; decimal ratio; int newWidth = 0; int newHeight = 0;
Update:
I did another analysis, and it seems that the problem is saving the thumbnail in the SQL Server database in the varbinary column. I am using a MemoryStream for this as shown below. If I save it to disk, it looks just fine. Here is my thumbnail from the database - http://s12.postimage.org/a7j50vr8d/Generated_Thumbnail.jpg
using (MemoryStream thumbnailStream = new MemoryStream()) { thumbnailBitmap.Save(thumbnailStream, System.Drawing.Imaging.ImageFormat.Jpeg); return thumbnailStream.ToArray(); }
Update - this problem has been resolved. The problem was the NHibernate mapping that I used for the varbinary column. I had to specify the type as "BinaryBlob" to make sure that there is no silent data truncation> 8KB.
nipps source share