c# - Display small image catalog in asp -
hi want put products catalog, how can crop picture small , save small , orginal?
try here:
c# thumbnail image getthumbnailimage
or here:
create thumbnail , reduce image size
update
for example can save image folder , can this:
var filename = "sourceimage.png"; using(var image = image.fromfile(filename)) { using(var thumbnail = image.getthumbnailimage(20/*width*/, 40/*height*/, null, intptr.zero)) { thumbnail.save("thumb.png"); } }
update
to resize proportionally try this:
public bitmap proportionallyresizebitmap (bitmap src, int maxwidth, int maxheight) { // original dimensions int w = src.width; int h = src.height; // longest , shortest dimension int longestdimension = (w>h)?w: h; int shortestdimension = (w<h)?w: h; // propotionality float factor = ((float)longestdimension) / shortestdimension; // default width greater height double newwidth = maxwidth; double newheight = maxwidth/factor; // if height greater width recalculate if ( w < h ) { newwidth = maxheight / factor; newheight = maxheight; } // create new bitmap @ new dimensions bitmap result = new bitmap((int)newwidth, (int)newheight); using ( graphics g = graphics.fromimage((system.drawing.image)result) ) g.drawimage(src, 0, 0, (int)newwidth, (int)newheight); return result; }
Comments
Post a Comment