c# - A generic error occurred in GDI+, Getting this exception in my code when i try to save optimized image on server -
here code below using redraw , save image.
bitmap bitmap = new bitmap(httpcontext.current.server.mappath( filepath + path.getfilename(filename))); int newwidth = 100; int newheight = 100; int iwidth = bitmap.width; int iheight = bitmap.height; if (iwidth <= 100) newwidth = iwidth; if (iheight <= 100) newheight = iheight; bitmap.dispose(); // once got information, we'll process it. // create image object using original width , height. // define pixel format (for rich rgb color). system.drawing.image objoptimage = new system.drawing.bitmap(newwidth, newheight, system.drawing.imaging.pixelformat.format16bpprgb555); // original image. using (system.drawing.image objimg = system.drawing.image.fromfile(httpcontext.current.server.mappath(filepath + filename))) { // re-draw image using newly obtained pixel format. using (system.drawing.graphics ographic = system.drawing.graphics.fromimage(objoptimage)) { var _1 = ographic; system.drawing.rectangle orectangle = new system.drawing.rectangle(0, 0, newwidth, newheight); _1.drawimage(objimg, orectangle); } // on below lines of code getting error while try execute // code after uploading image. if image size around 10 kb // not throw error if exceeds 10 kb will. //save optimized image objoptimage.save(httpcontext.current.server.mappath(filepath + "tempsubimages/" + filename), system.drawing.imaging.imageformat.png);** objimg.dispose(); } objoptimage.dispose(); // show optimized image details size. bitmap bitmap_opt = new bitmap(httpcontext.current.server.mappath(filepath + "tempsubimages/" + path.getfilename(filename))); byte[] bytes = system.io.file.readallbytes(httpcontext.current.server.mappath(filepath + "tempsubimages/" + path.getfilename(filename))); ui.basepage.temporaryfile = bytes; string[] arrcontenttype = new string[] { postedfile.contenttype, filename }; ui.basepage.temporarystrings = arrcontenttype; int iwidth_opt = bitmap_opt.width; int iheight_opt = bitmap_opt.height; bitmap_opt.dispose();
Comments
Post a Comment