public static void writeBitmapWithCompress(final String localFileName, Bitmap b){
int bytes = b.getByteCount();
ByteBuffer buffer = ByteBuffer.allocate(bytes); //Create a new buffer
b.copyPixelsToBuffer(buffer); //Move the byte data to the buffer
byte[] array = buffer.array();
// byte[] encodedString = Base64.encode(array, Base64.DEFAULT);
byte[] decodedString = Base64.decode(array, Base64.DEFAULT);
// Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
Timber.d(">> social localFileName"+ localFileName);
try {
FileOutputStream fileOutputStream = new FileOutputStream(localFileName);
fileOutputStream.write(decodedString);
fileOutputStream.flush();
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
getting exception at this line --> byte[] decodedString = Base64.decode(array, Base64.DEFAULT);
bad base64. Is other way to do this task without using any compression ?
stacktrace--- >
at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 02-08 at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:635) I/dalvikvm:
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:611)
at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:391)
at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:417)
at nl.changer.socialschools.common.Utils.resizeImage(Utils.java:408)
at nl.changer.socialschools.common.Utils.uploadPhotos(Utils.java:321) at nl.changer.socialschools.AsyncPostService.createPost(AsyncPostService.java:75) nl.changer.socialschools.AsyncPostService.onHandleIntent(AsyncPostService.java:50) at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:110) 02-08 android.os.Looper.loop(Looper.java:193) 02-08 11:41:36.214 android.os.HandlerThread.run(HandlerThread.java:61)
encodethe bytes to a base64 string. Notdecodeas you try to do now.