In my android app I am having user select an image file from his/her mobile, display it in a textview and then I am saving it in a json string before navigating to next page(navigating to next page is same as reloading the activity with new set of data).
I am using the below two methods for converting a Drawable to encoded string and to decode the string back to Drawable.
public String encodeImageToString(Drawable d) throws Exception{
Bitmap bm = ((BitmapDrawable) d).getBitmap();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] byteArrayImage = baos.toByteArray();
Toast.makeText(getBaseContext(), "Size After encoding to string:"+byteArrayImage.length, Toast.LENGTH_LONG).show();
String encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);
bm=null;
baos.close();
baos=null;
return encodedImage;
}
public Drawable decodeStringToImage(String encodedImage){
byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
Drawable d = new BitmapDrawable(getResources(),decodedByte);
Toast.makeText(getBaseContext(), "Size after decoding string to image: " + decodedByte.getByteCount(), Toast.LENGTH_LONG).show();
decodedByte = null;
return d;
}
The issue I am facing is that every time I navigate back to the page, the image quality decreases. And also the bytearray size as I display in encodeImageToString() using the Toast, keep on increasing with every reload.
My sequence of action is
-load image from selected file into textview ( compress the image while loading. I have not shared that code above)
-Once user navigates to next page, I save the textview image into base64 encoded String. Here I call method encodeImageToString(Drawable d) and convert image to string and store it in JSON String
-Once user navigates back to the page, I retrieve the string from the JSON String and then call decodeStringToImage(String s) to get back the Drawable. I then display that Drawable into textview.
The problem is that when image gets reloaded into the textview the quality decreases. Every reloaded decreases the quality. Also as I checked the bytearray size as I display in encodeImageToString() keeps on increasing.
Can someone please suggest if there is anything I am missing here. Reloading thhe image to string and then string back to image should have no impact on quality or size of the image. But that is not so in this case.
Each jpeg encoding operation will decrease the image quality, so you want to keep the number of encoding operations to a minimum.
Here is a naive way of looking at things: The result of encoding an image I is encode(I) -> I + δ where δ are compression artifacts. If you now encode this again, you will do this: encode(I + δ) : you waste time and space encoding compression artifacts.
Solution: When you display the image, also keep a copy of the encoded base64 string around. When the image is selected, just transfer this string. Don't reencode the image.
Related
So in my app I have possibility to take photo. What I want to do later is to sent this photo to server using API as Base64 String. Here's my code to encode bitmap (photo) to String :
public static String convertPhotoToBase(Bitmap bmp) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
Log.e(TAG, Base64.encodeToString(byteArray, Base64.DEFAULT));
return Base64.encodeToString(byteArray, Base64.DEFAULT);
}
Looks ok, right ? Well, it's not and I don't why String I'm receiving is not encoded correctly. I add, that bitmap is ok , cuz I can display it in ImageView without any problems.
String I'm getting looks like this :
iVBORw0KGgoAAAANSUhEUgAAA8AAAAZACAIAAAA5PLyzAAAAA3NCSVQICAjb4U/gAAAgAElEQVR4 nKS9WbbsOK4kagZ5DON9VM1/hncL9j7QEKTkHnFXKXOd8K2GBNETBEH+3//z/0mSBIgkAJpIfmhx kXQ6ABEkP/YPyPjT3SXe963b3f8AAEah28l2JYckwQUAEgDAyerDPtERZMpXZAJJGgyU7rjpDing dNoN6MOrHrm7S4o/CUGEkbzOUQgASAYAzOHIQAl0wam8KGab8bKMOTrPjurpFfdv0d3piUwDAZiZ iGpTd6Oa/PCSvJvqITgpCaSMJEhelIEY8CDw6C7pdpMUQzPBkHBe5gAsxytZ9nvTScoR4FGQKCmo TF6QJbi4AVwSjLyAK6h2Xbgk6f5z9/u+izRXQEVSuqmFIuGW5EqwA/MkA2Y3q+HfNUCRvK5/mnYu Rl8ApCs+9gSYxEXyn4vVOxurt4Q7OeRPdyMZgNnVbGBmwcIBHoA73lxUXhc8byb+5YFgkkB2DVjw SQwnW7DgwIATja6ApAFz9x1RnowqgfkIAHiFdMxBNfxBkUSFw7nIAUBySqSasS8kQDfkUgwo+CpY SNVzoB3AxezLEBLBACbgUWmD6zLSsl8sWVBxQcjmuNT8jNIZJHF7D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HQv2AUJMmWgzuWd/oslJwT9loNkBmOuRfr9h3YJ70Hxi40vmQGASjlFO0AigysCaYHq UHOSaACXt9dDDgZlJXClyxBszo4tmGKJp
It looks like correct Base64 string but if you check it - it's not. Do you have any idea why is that ? Is it bitmap issue ,or what ? Any help, please ?
use this method to encode the bitmap you want
public static String enBitmap64(Bitmap bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
bitmap.recycle();
byte[] array = stream.toByteArray();
return Base64.encodeToString(array, 0);
}
and this method to decode the string
public static Bitmap deBitmap64(String string) {
byte[] decodedString = Base64.decode(string, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
return decodedByte;
}
However, before using encode64 you need to know few things
Encode and decode bitmaps needs to be done in background (NOT IN THE MAIN THREAD) it hangs the UI specially if the bitmap was large, use Asynctask, Service or Runnable (Asynctask is best choice).
It's not recommended to encode large images and upload it as string to server, encode and decode only in two cases.
First, if all you images are small.
Second, if you have large images and somewhere you app you display it as thumbnail For exp; In friends search of Facebook you see small images(thumbnail) you click it becomes large(original image). so there is small image and large image, when you are in friends search page you only request(download) the small image (low resolution) from the server no need to request(download) such large image(high resolution), but the two images are stored in the server. the small one could be saved as encoded but NOT the large one, large images is to be upload to server though HttpClient, Volley or HttpURLConnection.. there are more
I have almost the same issue,
encoding and decoding were working perfectly on the java side.
But my Base64 string couldn't be decoded on the server side.
comparing different base64s helped me to see that my base64 break into lines so using following code helped to correct base64
base64string.replace("\n", ""));
I select image from gallery, convert into Base64 and sends to server. For JPEG image, it works fine; the image I upload from gallery on server same gets shown in server folder. However, when I upload PNG format image from mobile gallery, it doesn't show same on server; instead it creates black edges around it. I really don't know what's going wrong?
Also, my actual image is as equal as given JPEG image.
Reference images:
JPEG:
PNG:
I just want to get rid of BLACK borders which should not appear for PNG format images.
Below is my code snippet
FileInputStream mFileInputStream = null;
try {
mFileInputStream = new FileInputStream(imagePathFromSDCard);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int bytesRead = 0;
while ((bytesRead = mFileInputStream.read(b)) != -1) {
bos.write(b, 0, bytesRead);
}
Bitmap bitmap = safeImageProcessing.decodeFile(uri);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
byte[] ba = bos.toByteArray();
String encodedImage = Base64.encodeToString(ba, Base64.NO_WRAP);
//this line sends image base64 to server & there i decode into original
new ImageAsync().sendImageProcess(getActivity(), encodedImage, this);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
You want to upload image files. But you use BitmapFactory to make a Bitmap out of them first. Then you compress the bitmap to a jpg or png byte array. After that you base64 encode the bytes to a string which you upload.
What a waiste. And you have changed the files. Do away with the intermediate bitmap.
Instead load the files directly in a byte array. Then continue with the byte array as usual.
Having said that i think its a bad idea to base64 encode the bytes of a file first as it increases the amount of bytes that have to be transferred with 30%.
I am busy with a small android app. The appplication connects to a WCF using restful that in turn connects to a database. The application does work. Now I want to send a Image to the database.
[OperationContract]
[WebGet(UriTemplate = "sendImage/{seq}", ResponseFormat = WebMessageFormat.Json)]
string sendImage(string seq);
On the android application I encode a Image making use of BASE64.
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
TextView textView = (TextView) findViewById(R.id.defaults);
textView.setText(encodedImage);
This encryption does work. The problem is that I now what to send the string encodedImage to the WCF to write to the database. Thus the string is passed in the URI.
"htp://_____.__/serv/ManagementSystem.svc/sendImage/" + encodedImage
The problem is that the string that I get from encoded contains / characters.
/9J/DASDFkFASDF/.....
This causes a problem in the URI as it picks up the / as a change of parameter, thus picking up that it is not a valid request. Is there a way to remove the / without compromising the decoding or is there a better way of converting a image to a string and back to an image?
If you have control over the server side, I can at least think of two options:
1) After base64 encoding, replace all / with _, which is valid for url, has no particular pre-assigned meaning, and it is not used by base64. On the server side, you apply the opposite replace;
2) This is more straightforward that option 1, instead of get, you use put or post.
When i converting my bitmap to string using base64, got the result with 3 dots at the end of the string. why does it happen?
my base64 code is given below
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, baos);
byte[]imagedata= baos.toByteArray();
encodedImage = Base64.encodeToString(imagedata, Base64.DEFAULT);
and the string i got is
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAogBbADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK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IoZmkPSnFMdBTlQkcikHQjjQE805o89qkEfpUirSCxV2flSBatMOKiK0gIwMUFafigjNCGQlc00oQKsBcimMOtMCALnNKVqVBmgrxSsIjC0bakVSKcVGKdgICnWljj9smphHmnxripAg2cUBandaaFpoCPbRipCM03bVAMYU0xZHNTYxQKCWQpHg0pXFTGopOoFNaCDHFIRSg0YoAZtz0pVHBpQMUu3NMBAKD3pSCKMZoBjMUlOYUijOaQAozmmk5NPzgVH1Y00wFP0pMcUtNNNAJ2pCmelONOXuKGK5AyFaQ5qyRwajKipAruKApNSsgFKgwaLgR+WamSLIpUHNTIABTuAxI8U8LmnKmaeq4zSuFhuOKT61LgHtSFMc9qVxrY9pxinUg5pa6bnjgBRiinD9aZIqLkGnbKQcc09WFBLmgC4FPRcd6UEEUooM3IQdaMikc01ByeKOYxlIkUZFSRjnFPhiyoNWEhqX...
there are no any dot at the end its just indicate there are more string below. if you want to show complete String then take one Scrollview and inside it take Textview. and Show your String in TextView instead of logcat. Now you can see complete text of your Bitmap.
thats it...
Atlast i got the solution. The string contain full characters,the logcat shows only a part of the string,thats why it showing s dots(...) at the end
I have the code below to decode a bitmap to a base64 string.
for(String e:paths)
{
String usepath=e.replace("%", "//");
Bitmap m=BitmapFactory.decodeFile(usepath);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
m.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String bb= Base64.encodeToString(b, Base64.NO_WRAP);
Log.e("Photo", bb);
String usepath prints like
/mnt/sdcard/DCIM/Camera/IMG_20140424_132023.jpg
I have saved the image on my pc and used an online tool to decode it to base64 and i got a long string of around 650kb(after uploading to google app engine) yet the string i get using the above code is like 10% of that and does not display the image .
But i can use the same image path to set an image view and it works like below
Bitmap bm= BitmapFactory.decodeFile(usepath);
holder.imageItem.setImageBitmap(bm);
Any reasons why the base64 encoding failing?
Ronald
Try adding the flag Base64.URL_SAFE to the encoding method.
Consider also that if the image is too large you may not get all the bytes you need in the String (you may try writing to a temp file previous to send the content).