java - Problems with NativeDecodeByteArray in Android Bitmap.class -


i decoding base 64 encoded images on android(java). works of images, of image binaries returns null. if use online decoder, binary in question works fine, tells me format correct.

the piece of code on base64.class file messes

if (!decoder.process(input, offset, len, true)) {     throw new illegalargumentexception("bad base-64"); }  // maybe got lucky , allocated enough output space. if (decoder.op == decoder.output.length) {     return decoder.output; }  // need shorten array, allocate new 1 of // right size , copy. byte[] temp = new byte[decoder.op]; system.arraycopy(decoder.output, 0, temp, 0, decoder.op); return temp; 

for images fail, goes through the

maybe got lucky check, , returns decoder.output , directly jumps return temp, inturn returns null

. images work not enter if , returns non null temp variable. there known issue this?

update

invoking code

 //this decodedstring null     byte[] decodedstring = base64.decode(                         data, base64.default);                 bitmap setbmppath = bitmapfactory.decodebytearray(decodedstring, 0,                         decodedstring.length);                  qimage.setimagebitmap(setbmppath);  

edit

turns out method returning value. @davidehrmann help. error in next step converting decodestring bitmap.

public static bitmap decodebytearray(byte[] data, int offset, int length, options opts) {         if ((offset | length) < 0 || data.length < offset + length) {             throw new arrayindexoutofboundsexception();         }         bitmap bm = nativedecodebytearray(data, offset, length, opts);         if (bm == null && opts != null && opts.inbitmap != null) {             throw new illegalargumentexception("problem decoding existing bitmap");         }         return bm;     } 

here bm returning null! call

bitmap bm = nativedecodebytearray(data, offset, length, opts); 

is null since opts != null && opts.inbitmap != null not true not throw illegalargumentexception , returns bm null. ideas why?

update

i see error in log says skia --decoder decode returns false. i've tried every answer every such question on , still not working .

my base64 code: http://pastebin.com/pnbqqg97

if posted on website decodes online, spits out right image, bitmap decoder fails.

update - solution problem

as turns out, binary encoding being done on png file, , being reconverted bmp file, bmp bmp seems work in cases. surprises png's converted work! me having original image bmp problem because of size, there way can decode png base 64 in android reliably without using bitmap factory>?

answer

turns out image invalid @ 1 character point :o reason wasnt picked online decoder in code shown above. make sure check code see not replacing of image base64 characters. 1 off can set go haywire found out

take @ why bitmapfactory.decodebytearray return null?. what's bit strange data pastebinned looks valid png.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -