c# - Save image on disk from byte array (using EF), A generic error occurred in GDI+ -


i'm working on winforms program byte array database, transform image , save on disk.

the picture displayed in picturebox element when try save file, code throw error : "the generic error occurred in gdi+". picture generated in folder, unreadable (weighs 0 octets).

var profilimage = (from user in _context.mytable                             user.id == itemdata.id                             select user.profilimage).firstordefault();  image dcimage = bytearraytoimage(profilimage); this.picturebox1.image = dcimage;  dcimage.save(this.tb_choose_folder.text + @"\test.jpg", imageformat.jpeg); 

method bytearraytoimage()

// convert byte array image     private image bytearraytoimage(byte[] bytearrayin)     {         if(bytearrayin == null)         {             throw new nullreferenceexception("bytearrayin");         }          using (memorystream mstream = new memorystream(bytearrayin))         {             return image.fromstream(mstream);         }     } 

and here how tranform image byte array :

system.drawing.image image = system.drawing.image.fromfile(@"myfolder\test_1.jpg");         system.io.memorystream ms = new system.io.memorystream();         image.save(ms,system.drawing.imaging.imageformat.jpeg);          var imagebytearray = ms.toarray(); 

imagebytearray put in sql server image type field

thanks advices

you don't need of that. bytes jpeg file; can read , write them disk using file.readallbytes() , file.writeallbytes().


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -