C# ByteArray to Image -
i need convert byte[]
image
, cannot make work in c#. if save bytearray
file this:
using (system.io.filestream fs = system.io.file.create("test.jpg")) { fs.write(bytearray, 0, (int)lenght); fs.close(); }
and test.jpg shows properly. when try make image bytearray this:
memorystream ms = new memorystream(bytearray); picturebox1.image = image.fromstream(ms);
it shows black box.
i guess 1 problem since creating test.jpg, doesn't have data , bytearray empty.
do :-
byte[] filedata = null; using (var fs = new filestream("c:\\1\\roses.jpg", filemode.open, fileaccess.read)) { var totallength = (int)fs.length; using (var binaryreader = new binaryreader(fs)) { filedata = new byte[totallength]; fs.read(filedata, 0, totallength); fs.close(); } memorystream ms = new memorystream(filedata); picturebox1.image = image.fromstream(ms); }
Comments
Post a Comment