c# - How to Resize Image and save in folder? -


i tried this:

string str = system.io.path.getfilename(txtimage.text); string pth = system.io.directory.getcurrentdirectory() + "\\subject"; string fullpath = pth + "\\" + str; image newimage = clsimage.resizeimage(fullpath, 130, 140, true); newimage.save(fullpath, imageformat.jpeg); 

public static image resizeimage(string file, int width, int height, bool onlyresizeifwider) { if (file.exists(file) == false) return null; try { using (image image = image.fromfile(file)) { // prevent using images internal thumbnail image.rotateflip(rotatefliptype.rotate180flipnone); image.rotateflip(rotatefliptype.rotate180flipnone); if (onlyresizeifwider == true) { if (image.width <= width) { width = image.width; } } int newheight = image.height * width / image.width; if (newheight > height) { // resize height instead width = image.width * height / image.height; newheight = height; } image newimage = image.getthumbnailimage(width, newheight, null, intptr.zero); return newimage; } } catch (exception ) { return null; } } 

running above code, image 4-5 kb in size poor image quality. original image file no more 1.5 mb large. how can improve image quality of results?

i think should use image resizer, free , resizing image easy using it.

var settings = new resizesettings { maxwidth = thumbnailsize, maxheight = thumbnailsize, format = "jpg" }; settings.add("quality", quality.tostring()); imagebuilder.current.build(instream, outstream, settings); resized = outstream.toarray(); 

you can install using nuget package manager.

pm> install-package imageresizer 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -