java - Reading an image as byte array with Android: skImageDecoder::Factory returned null -
i have spring mvc web service returns image byte array. output in json format. format png here's code snippet image.
bufferedimage img = imageio.read(new file(caminho.replace("/", "//"))); imagem = ((databufferbyte) img.getraster().getdatabuffer ()).getdata();
when run server, output:
[{"id":0,"caminhomdpi":null,"caminhohdpi":"c:/users/marcos/pictures/postos/drawable-
mdpi/esso_logo.png","caminhoxhdpi":null,"caminhoxxhdpi":null,"imagem":"aaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaa....]
eventually, other symbols appear on "imagem" field. suppose right, i'm not
sure.
on android app, have routine download image , store blob in database. receive json format , transform class jackson. i've logged "imagem" field , looks same.
my problem can't transform image. here's code snippet:
byte[] img_bandeira = cursor.getblob(cursor.getcolumnindex("img_bandeira")); bitmap bmpbandeira = bitmapfactory.decodebytearray(img_bandeira, 0, img_bandeira.length); imageview ivbandeira = (imageview) view.findviewbyid(r.id.ivbandeira); ivbandeira.setimagebitmap(bmpbandeira);
all message: skimagedecoder::factory returned null.
i've looked @ other similar posts, tried change lines, nothing happened. don't know what's going on here. in advance.
i solved it. in server, image should sent this:
bytearrayoutputstream baos = new bytearrayoutputstream(); bufferedimage img = imageio.read(new file(caminho.replace("/", "//"))); imageio.write(img, "png", baos); baos.flush(); string base64string = base64.encode(baos.tobytearray()); baos.close();
in app, should read this:
public static bitmap getimage(byte[] imagearray) { bytearrayinputstream bytearrayinputstream = new bytearrayinputstream(imagearray); bitmap bitmap = bitmapfactory.decodestream(bytearrayinputstream); return bitmap; }
thank you, ;)
Comments
Post a Comment