c# - How to resize images to display from database -


i doing small project have display images database listview. passing image id,width,and height querystring parameter.

<asp:image id="image1" runat="server" imageurl='<%#"~/handler/imagehandler.ashx?imgheight=150&imgwidth=200&imgid="+eval("image_id")%>' height="150px" width="200px"/> public void processrequest (httpcontext context)      {      string imgwidth = context.request.querystring["imgwidth"];     string imgheight = context.request.querystring["imgheight"];     string imageid = context.request.querystring["imgid"];     if (imgwidth != string.empty && imgheight != string.empty && (imgwidth != null && imgheight != null))     {         if (!system.web.ui.webcontrols.unit.parse(imgwidth).isempty && !system.web.ui.webcontrols.unit.parse(imgheight).isempty)         {             //create unit object height , width. convert parameter passed in differen unit pixel, inch generic unit.             system.web.ui.webcontrols.unit widthunit=system.web.ui.webcontrols.unit.parse(imgwidth);             system.web.ui.webcontrols.unit heightunit = system.web.ui.webcontrols.unit.parse(imgheight);             //after ???         }      } } 

when display image directly database images stretch , doesn't good, because image size large. need display images thumbsnail in image gallery.

you use getthumbnailimage method

refer code

public void generateimage(int iwidth,int iheight,byte[] imagebytes) { system.drawing.image image = bytearraytoimage(imagebytes)   // create actual thumbnail image         system.drawing.image thumbnailimage = image.getthumbnailimage(iwidth, iheight, new system.drawing.image.getthumbnailimageabort(thumbnailcallback), intptr.zero);          // make memory stream work image bytes         memorystream imagestream = new memorystream();          // put image memory stream         thumbnailimage.save(imagestream, system.drawing.imaging.imageformat.jpeg);          // make byte array same size image         byte[] imagecontent = new byte[imagestream.length];          // rewind memory stream         imagestream.position = 0;          // load byte array image         imagestream.read(imagecontent, 0, (int)imagestream.length);          // return byte array caller image type         response.contenttype = "image/jpeg";         response.binarywrite(imagecontent);     }      public bool thumbnailcallback()     {         return true;     } public image bytearraytoimage(byte[] bytearrayin) {      memorystream ms = new memorystream(bytearrayin);      image returnimage = image.fromstream(ms);      return returnimage; } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -