java - Base64 Encoding takes too long time in Android -
i'm capturing image camera. save file in public photo directory , save uri
file.
i want save image in base64
string
, put on hashmap
put in xml file later.
protected void doinbackground(void...voids) { options.injustdecodebounds = false; //bitmap bmp = bitmapfactory.decodefile(imagefilepath,options); inputstream in = null; try { in = getcontentresolver().openinputstream(uri.parse(mcurrentphotopath)); } catch (filenotfoundexception e) { e.printstacktrace(); } options.insamplesize = 2; bitmap image = bitmapfactory.decodestream(in,null,options); int imgheight = image.getheight(); int imgwidth = image.getwidth(); while(imgheight>2000){ imgheight = imgheight / 2; } while(imgwidth>2000){ imgwidth = imgwidth / 2; } bitmap test = bitmap.createscaledbitmap(image,imgwidth,imgheight,false); string stest = base64encodedecode.encodetobase64(test); items.put("image",base64encodedecode.encodetobase64(test); return null; }
the base64
takes long encode it. encodetobase64 method
public string encodetobase64(bitmap image) { bytearrayoutputstream baos = new bytearrayoutputstream(); image.compress(bitmap.compressformat.jpeg, 100, baos); byte[] b = baos.tobytearray(); return base64.encodetostring(b, base64.default); }
can tell me if wrong while encoding?
i hope problem clear.
kind regards!
if getting !!! failed binder transaction !!!
error because passing data other activity
, there limit of how can send. try compressing image 50% or 30% image.compress(bitmap.compressformat.jpeg, 50, baos);
Comments
Post a Comment