c# - Argument Exception while converting byte array to image -


i convert image byte[] using code (form.cs):

private void button1_click(object sender, eventargs e) {     form1 fom = new form1();      imageconverter converter = new imageconverter();     byte[] imgarray = (byte[])converter.convertto(fom.panel1.backgroundimage, typeof(byte[]));      imagedata img = new imagedata     {         classname = textbox1.text,         password = textbox2.text,         image = imgarray,     };      using (boarddatabaseentities dc = new boarddatabaseentities())     {         dc.imagedatas.add(img);         dc.savechanges();         messagebox.show("saved database");           }      this.close(); } 

then, trying convert image::

protected void button1_click(object sender, eventargs e) {     using (boarddatabaseentities dc = new boarddatabaseentities())     {         var v = dc.imagedatas.where(a => a.classname.equals(textbox3.text) && a.password.equals(textbox4.text)).firstordefault();         if (v != null)         {             byte[] byt = v.image;              imageconverter ic = new imageconverter();             system.drawing.image img = (system.drawing.image)ic.convertfrom(byt);              string name = v.classname;              try             {                 var ratio = (double)100 / img.height;                 int imageheight = (int)(img.height * ratio);                 int imagewidth = (int)(img.width * ratio);                  system.drawing.image.getthumbnailimageabort dcallback = new system.drawing.image.getthumbnailimageabort(thumbnailcallback);                 system.drawing.image thumbnailimg = img.getthumbnailimage(imagewidth, imageheight, dcallback, intptr.zero);                  thumbnailimg.save(path.combine(server.mappath("~/thumbnail"), name), imageformat.jpeg);                 thumbnailimg.dispose();                  //here code uploaded images                 populateimage();             }             catch (exception ex)             {                  throw;             }          }     } } 

it giving me argumentexception error in line:

system.drawing.image img = (system.drawing.image)ic.convertfrom(byt); 

it says, parameter invalid.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -