c# - Resizing High Quality images for web -


hi guys resizing images in c# , saving them .png.

public static bitmap resize(int x, int y, image p) {     bitmap img = new bitmap(x,y);     using (graphics gr = graphics.fromimage(img))     {         gr.smoothingmode = smoothingmode.highquality;         gr.interpolationmode = interpolationmode.highqualitybicubic;         gr.pixeloffsetmode = pixeloffsetmode.highquality;         gr.drawimage(p, new rectangle(0, 0, x, y));     }     return img; } 

the problem when user uploads high quality image such images high end smartphones such galaxys, iphones etc filesize of resulting resized image quite high. have constructed table of resized images file size , pixel size.

1) img1  1280 * 666px => 458 kb 2) img1  300 * 399px => 221kb 3) img2  1280 * 1444px => 2.08mb 4) img2  300 * 451px => 327kb 

i know have interpolation , smoothing set high quality example purposes , saving images .png preserve transparency. setting should change obtain image of reasonable quality , filesize ideal html pages. end goal making compromise between image quality , filesize. please point me to link demonstrating filsesize vs quality comparison quality of resized images can make choice myself.

there 1 option can play with, pixelformat.

using (bitmap bmp = new bitmap(x, y,           system.drawing.imaging.pixelformat.format32bppargb)) {     using (graphics gr = graphics.fromimage(bmp))     {          gr.smoothingmode = smoothingmode.highquality;         gr.interpolationmode = interpolationmode.highqualitybicubic;         gr.pixeloffsetmode = pixeloffsetmode.highquality;         gr.drawimage(src, new rectangle(0, 0, x, y));     } } 

use 32 bit argb if need alpha channel (e.g. image transparent). can query img.pixelformat see if image contains alpha channel! in case don't have save png , can go jpg result in lot smaller files!

normal jpg use format24bpprgb.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -