![]() ![]() ThumbnailBitmap.Save(toStream, image.RawFormat) ThumbnailGraph.DrawImage(image, imageRectangle) Var imageRectangle = new Rectangle(0, 0, newWidth, newHeight) ThumbnailGraph.InterpolationMode = InterpolationMode. ThumbnailGraph.SmoothingMode = SmoothingMode. ThumbnailGraph.CompositingQuality = CompositingQuality. Var thumbnailBitmap = new Bitmap (newWidth, newHeight) public void ResizeImage( double scaleFactor, Stream fromStream, Stream toStream) Also you can see that this code tries to save as much quality as possible. This code doesn’t use GetThumbnailImage method and operates therefore on full size image. Now let’s see the code that makes clean resizing. It has less impact on your system and it wants less resources than resizing full size image down to thumbnail size. Use GetThumbnailImage to create small thumbnails. To get image with this size you should use 0.07 as scaling factor. Let’s follow now MSDN Library suggestion and make thumbnail that is 7% of original image. I have on advice too: don’t trust everything you find in web, even if it has very high position in search engine results ( Google: asp.net resize image). It might be better to scale the main image (instead of scaling the embedded thumbnail) by calling the DrawImage method. If you request a large thumbnail image (for example, 300 x 300) from an Image that has an embedded thumbnail, there could be a noticeable loss of quality in the thumbnail image. The GetThumbnailImage method works well when the requested thumbnail image has a size of about 120 x 120 pixels. If the Image does not contain an embedded thumbnail image, this method creates a thumbnail image by scaling the main image. If the Image contains an embedded thumbnail image, this method retrieves the embedded thumbnail and scales it to the requested size. It is directly copy-pasted from MSDN library: Thumbnail.Save(toStream, image.RawFormat) Īwful, isn’t it? Now I tell you a little secret. Var thumbnail = image.GetThumbnailImage(newWidth, newHeight, abort, IntPtr.Zero) ![]() GetThumbnailImageAbort(ThumbnailCallback) Var newHeight = ( int )(image.Height * scaleFactor) Var newWidth = ( int )(image.Width * scaleFactor) Image.GetThumbnailImageĪs a first thing let’s use Image.GetThumbnailImage to get new version of original image that is four times smaller (512×384). This file contains thumbnail image and let’s see how previously pointed example fails. Be aware – size this file is about 1.6MB.Ĭlick on the image to see it in original size. I am on this photo too (guess which one). Our original image here is taken during Wacken Open Air 2005. This causes hard loss of quality and resized image look awful. It takes small thumbnail image and resizes it larger. If you take image with high resolution and resize it to 50% then using Image.GetThumbnailImage method may produce the result we expect. These thumbnails are embedded in original image and are usually small by their dimensions. One those functionalities is generating thumbnails of images. They can do many tricks we cannot even imagine if we are dumb users. In this post I will show you how to resize images without negative side effects.Ĭameras today are powerful tools. You can easily create crappy images if you follow the code examples in previously pointed article. There are many people out there who mistakenly think that Image.GetThumbnailImage is best choice for image resizing. ASP.NET provides us with System.Drawing namespace where we can find classes we can use to manipulate with images. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |