c# - Converting image from project folder -
i trying convert image in image folder , image name defaultimage
, update database table.
but having problem in line of code:
i change code using this:
image uploaded6 = image.fromfile("/image/defaultimage.jpg");
instead of this:
system.drawing.image uploaded = system.drawing.image.fromstream(
~/images/defaultimage);
i getting error of filenotfoundexception unhandled user code
i have tried method using fileupload control , working fine not sure how convert image in folder.
how image folder in order convert using method shown below.
image uploaded6 = image.fromfile("/image/defaultimage.jpg"); //system.drawing.image uploaded = system.drawing.image.fromstream(); system.drawing.image newimage = new bitmap(1024, 768); using (graphics g = graphics.fromimage(newimage)) { g.interpolationmode = interpolationmode.highqualitybicubic; g.drawimage(uploaded, 0, 0, 1024, 768); } byte[] results; using (memorystream ms = new memorystream()) { imagecodecinfo codec = imagecodecinfo.getimageencoders().firstordefault(c => c.formatid == imageformat.jpeg.guid); encoderparameters jpegparms = new encoderparameters(1); jpegparms.param[0] = new encoderparameter(encoder.quality, 95l); newimage.save(ms, codec, jpegparms); results = ms.toarray(); } string sqlimage = "update memberreport set image1 = @data memberreportid = '" + session["memberreportid"] + "'"; sqlcommand cmdimage = new sqlcommand(sqlimage); cmdimage.parameters.addwithvalue("@data", results); insertupdatedata(cmdimage);
i guess problem relative paths, instead of
image uploaded6 = image.fromfile("/image/defaultimage.jpg");
you should provide local path, can way:
image uploaded6 = image.fromfile(server.mappath("~/image/defaultimage.jpg"));
Comments
Post a Comment