The above function will cover most of them, but you still have to worry about saving. Maintaining aspect ratio is left as an exercise for the reader (actually, I just don't think it's this function's job to do that for you).Īlso, this is a good article describing some of the pitfalls with image resizing. graphics.PixelOffsetMode affects rendering quality when drawing the new image.graphics.SmoothingMode specifies whether lines, curves, and the edges of filled areas use smoothing (also called antialiasing) - probably only works on vectors.graphics.InterpolationMode determines how intermediate values between two endpoints are calculated.graphics.CompositingQuality determines the rendering quality level of layered images.SourceCopy specifies that when a color is rendered, it overwrites the background color. graphics.CompositingMode determines whether pixels from a source image overwrite or are combined with background pixels.Compositing controls how pixels are blended with the background - might not be needed since we're only drawing one thing.destImage.SetResolution maintains DPI regardless of physical size - may increase quality when reducing image dimensions or when printing.wrapMode.SetWrapMode(WrapMode.TileFlipXY) prevents ghosting around the image borders - naïve resizing will sample transparent pixels beyond the image boundaries, but by mirroring the image we can get a better sample (this setting is very noticeable).Graphics.DrawImage(image, destRect, 0, 0, image.Width,image.Height, GraphicsUnit.Pixel, wrapMode) WrapMode.SetWrapMode(WrapMode.TileFlipXY) Using (var wrapMode = new ImageAttributes()) Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality Graphics.SmoothingMode = SmoothingMode.HighQuality Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic Graphics.CompositingQuality = CompositingQuality.HighQuality Graphics.CompositingMode = CompositingMode.SourceCopy Using (var graphics = Graphics.FromImage(destImage)) Var destImage = new Bitmap(width, height) ĭestImage.SetResolution(image.HorizontalResolution, image.VerticalResolution) Var destRect = new Rectangle(0, 0, width, height) Public static Bitmap ResizeImage(Image image, int width, int height) / Resize the image to the specified width and height. This will perform a high quality resize: ///
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |