byte[] to image using Xamarin.Android -


i know, old question, i've got problems encoding byte[] bitmap...

background: i'm writing andoid-app receives picturebytes via udp, encodes them bitmap , displays picture in image view.

since functions didn't work, cancelled udp-connection testing , wrote image-bytes in huge variable. they're correct... function returns "null". function i'm using:

    public bitmap bytearraytoimage(byte[] imagedata)     {         var bmpoutput = bitmapfactory.decodebytearray(imagedata, 0, imagedata.length);         return bmpoutput;     } 

another function tried out:

    public bitmap bytearraytoimage2(byte[] imagedata)     {         bitmap bmpreturn;         bmpreturn = (android.graphics.bitmap) android.graphics.bitmap.fromarray<byte>(imagedata);         return bmpreturn;     } 

a function found in internet:

public static bitmap bytestouiimage (byte[] bytes) {     if (bytes == null)         return null;      bitmap bitmap;       var documentsfolder = environment.getfolderpath (environment.specialfolder.personal);      //create folder images if not exists     system.io.directory.createdirectory(system.io.path.combine (documentsfolder, "images"));      string imatge = system.io.path.combine (documents, "images", "image.jpg");       system.io.file.writeallbytes(imatge, bytes.concat(new byte[]{(byte)0xd9}).toarray());      bitmap = bitmapfactory.decodefile(imatge);      return bitmap; } 

most unfortunately, last function didn't work well, here have admit, bit confused 'documents' in string imatge = system.io.path.combine (documents, "images", "image.jpg"); got error , changed documentsfolder since guess, should (or could) right....

thank in advance help

it seems, found error... stored public bitmap bytearraytoimage(byte[] imagedata) in class. don't know why, when decode bytearray in class receives array, works fine... if knows reason, feel welcome let me know, i'm happy ;-)


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -