c# - Converting byte[] to image Windows Phone -
i have little problem when want "create" image byte array image.source (xaml)... firs save byte array web
string pomocna = responses.getvalue("slika").tostring(); byte[] pomocnopolje = new byte[pomocna.length]; int brojac = 0; foreach (char in pomocna) { pomocnopolje[brojac] = byte.parse(a.tostring()); brojac++; } nova.slika = pomocnopolje;
and set image source
stranica.slika.source = converttobitmapimage(nova.slika)
the problem occur on converttobitmapimage method
public static bitmapimage converttobitmapimage(byte[] image) { var bitmapimage = new bitmapimage(); var memorystream = new memorystream(image); bitmapimage.setsource(memorystream); homecoming bitmapimage; }
on line
bitmapimage.setsource(memorystream);
does knows how prepare it? ahead
if byte[] image
jpeg , want maintain memory stream this:
public static bitmapimage converttobitmapimage(byte[] image) { writeablebitmap wb = null; using (memorystream ms = new memorystream(image)) { seek { wb = microsoft.phone.picturedecoder.decodejpeg(ms); } grab (exception ex) { string error_message = ex.message; } } homecoming convertwbtobi(wb); } // converts writeablebitmap bitmapimage private bitmapimage convertwbtobi(writeablebitmap wb) { if(wb == null) homecoming null; bitmapimage bi; using (memorystream ms = new memorystream()) { wb.savejpeg(ms, wb.pixelwidth, wb.pixelheight, 0, 100); bi = new bitmapimage(); bi.setsource(ms); } homecoming bi; }
c# windows-phone-8
No comments:
Post a Comment