Phonegap Picture Base64 Android
Solution 1:
Can you try to increase the Image Quality. I remember reading some android phones have issues if the quality is set to low. I know it is a long shot but worth the try :)
Solution 2:
I believe console.log has a limit as to the number of characters it can print. What happens when you set the data as the source of an image tag like:
functiononSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}
Also, you may want to try writing the data out to a file.
Solution 3:
I have faced the same problem in android, What the exact problem is_ When i encode image into its corresponding Base64
& if the image size is more(2mb or more... & also depends on image quality & camera quality, may be taken from 2MP or 5MP or may be 8MP camera) then it encounter problem to convert full image into Base64... you must have to decrease the size of the concern image! I have give my working Android code
through which i have achieved it_
Get Base64 image String
ByteArrayOutputStreambaos=newByteArrayOutputStream();
Bitmap mBitmap= newdecodeFile("<PATH_OF_IMAGE_HERE>");
mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
int i=b.length;
String base64ImageString=android.util.Base64.encodeToString(b, 0, i, android.util.Base64.NO_WRAP);
Convert to proper bitmap
/**
*My Method that reduce the bitmap size.
*/private Bitmap decodeFile(String fPath){
//Decode image size
BitmapFactory.Options opts = new BitmapFactory.Options();
//opts.inJustDecodeBounds = true;
opts.inDither=false; //Disable Dithering mode
opts.inPurgeable=true; //Tell to gc that whether it needs free memory, the Bitmap can be cleared
opts.inInputShareable=true; //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future
opts.inTempStorage=new byte[1024];
BitmapFactory.decodeFile(fPath, opts);
//The new size we want to scale tofinalint REQUIRED_SIZE=70;//or vary accoding to your need...//Find the correct scale value. It should be the power of 2.int scale=1;
while(opts.outWidth/scale/2>=REQUIRED_SIZE && opts.outHeight/scale/2>=REQUIRED_SIZE)
scale*=2;
//Decode with inSampleSize
opts.inSampleSize=scale;
return BitmapFactory.decodeFile(fPath, opts);
}
I hope this will help other buddies that are facing the same problem... Thanks!
Post a Comment for "Phonegap Picture Base64 Android"