Is my encoding of bitmap usable for other platforms? - java

My question is is an encoded string generated with the code below usable on another platforms and if not - how do I make it? The code is working good on android, but I am not sure what will happen if I try to expand the project.
This is the code for generating the string:
private String BitMapToString(Bitmap bitmap){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos);
byte[] b = baos.toByteArray();
String imageEncoded = Base64.encodeToString(b, Base64.NO_WRAP);
return imageEncoded;
}
And this is the code for decoding it:
private Bitmap StringToBitMap(String encodedString){
byte[] decodedByte;
try {
decodedByte = Base64.decode(encodedString, 0);
} catch(Exception e) {
return null;
}
return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
}
I'm sending the string to the database and retrieving it and everything works just fine hence I can display the image. But is it usable elsewhere? And if not - how do I make it?

Related

Bad Base - 64 Error when trying to send an Image

I am looking to share a screenshot of a page between two devices. The screenshot is stored in a Bitmap and then I am converting it to a byte array which is then converted to a String in Base 64. The String is then sent over to a handler which will display the image. After I try to decode the image it is giving me a: java.lang.IllegalArgumentException: bad base-64
I have already tried to send the images in different ways and have tried all the different Base 64 methods such as Base64.DEFAULT, URLSAFE, NOPADDING etc...
Here is where I am creating the screenshot and sending:
Bitmap b =
Screenshot.takescreenshotofRootView(MainActivity.imageView);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.PNG,100,baos);
byte[] bytea = baos.toByteArray();
String temp = Base64.encodeToString(bytea, Base64.DEFAULT);
sendReceive.write(temp.getBytes());
This is where I am handling that data
Handler handler = new Handler(new Handler.Callback() {
#Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_READ:
MainActivity.imageView.setImageBitmap(bitm);
byte[] readBuff = (byte[]) msg.obj;
String tempMsg = new String(readBuff, 0, msg.arg1);
byte [] encodeByte = Base64.decode(tempMsg,Base64.URL_SAFE);
Bitmap bitms
= BitmapFactory.decodeByteArray(encodeByte,0,encodeByte.length);
MainActivity.imageView.setImageBitmap(bitms);
break;
}
return true;
}
});
You might be getting an OutOfMemoryError without realizing it, rendering your base64 string invalid. You should wrap your code with a try/catch block to see if that is happening. Here is an example in some code of mine:
String imageString = "";
try {
if (this.theBitmap != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
this.theBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] bytes = stream.toByteArray();
imageString = Base64.encodeToString(bytes, Base64.DEFAULT);
}
}catch(OutOfMemoryError E){
Log.e("MyApp", "Out Of Memory error");
}

can't create a image file from BASE64

Well, i'm trying to send a picture from android to java, if i make it with compression it works really good, but i need to make it without compression beacuse i need a good or normal quality.
FixBitmap is my current Bitmap picture
//Android
FixBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byteArray = byteArrayOutputStream.toByteArray();
ConvertImage = Base64.encodeToString(byteArray, Base64.DEFAULT);
Log.e(TAG,"LENGTH"+ConvertImage.length());
Length 43388
//Java
try{
String file=request.getParameter("image_data");
String filename=rt.getId()+"_"+rt.getName()+".png";
BufferedImage image = null;
byte[] imageByte;
BASE64Decoder decoder = new BASE64Decoder();
imageByte = decoder.decodeBuffer(file);
ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
image = ImageIO.read(bis);
bis.close();
File outputfile = new File(filename);
ImageIO.write(image, "png", outputfile);
Path destinationFile = Paths.get(getServletContext().getRealPath("/")+"uploads\\", filename);
Files.write(destinationFile,imageByte);
}catch(Exception ex){
System.out.println("Error :"+ex.getMessage());
}
This code actually works as i said, but the compression make it looks in a very bad quality, so i tried to make it without compression, just converting my bitmap to a byte array, just like this
ByteBuffer buffer = ByteBuffer.allocate(FixBitmap.getRowBytes() *
FixBitmap.getHeight());
FixBitmap.copyPixelsToBuffer(buffer);
byteArray = buffer.array();
ConvertImage = Base64.encodeToString(byteArray, Base64.DEFAULT);
Log.e(TAG,"LENGTH"+ConvertImage.length());
Length 252107
The code on my java side it's the same but now it doesn't work, it just shows me this error :
java.lang.IllegalArgumentException: image == null!
So I decided to print the length because maybe there is some restrictions about this...
so I hope you can help me with this (just send/get the picture without compression)

How could I convert png binary data into bmp binary data in JAVA?

I got my binary data from database which is in PNG format. Now, I need to change the format to BMP and then convert it to a string by Base64.
My logic is PNG binary-->BMP binary-->BMP base64 String.
My Code is as below. The input "data" is the PNG binary, imageFormat="BMP".
public static String imageToBase64 (byte[] data, String imageFormat) throws IOException{
BufferedImage imag=ImageIO.read(new ByteArrayInputStream(data));
ByteArrayOutputStream baos=new ByteArrayOutputStream(1000);
ImageIO.write(imag, imageFormat, baos);
String base64String=Base64.encodeBytes(baos.toByteArray());
return base64String;
}
However, the result always return empty. Can anyone help me to solve this problem?
Thanks
You need to use the Java API to write to a new BMP file. Based on your code this is how it does what you asked.
public static String imageToBase64(byte[] data, String imageFormat) throws IOException {
BufferedImage imag = ImageIO.read(new ByteArrayInputStream(data));
BufferedImage bmpImg = new BufferedImage(imag.getWidth(), imag.getHeight(), BufferedImage.TYPE_INT_RGB);
bmpImg.createGraphics().drawImage(imag, 0, 0, Color.WHITE, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bmpImg, imageFormat, baos);
String base64String = Base64.getEncoder().encodeToString(baos.toByteArray());
return base64String;
}
Please note I used "bmp" (lowercase) instead of "BMP". Not sure if this matters. Enjoy.

Bitmap image to base64 conversion

I am trying to convert a bitcode image to base64 format. I tried to code like
public static String encodeToBase64(Bitmap image, Bitmap.CompressFormat compressFormat, int quality)
{
ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
image.compress(compressFormat, quality, byteArrayOS);
return Base64.encodeToString(byteArrayOS.toByteArray(), Base64.URL_SAFE);
}
generated response is below which does not give me image again.
can someone provide some pointers here? What I might be doing wrong?
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQ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drZ4zjPzZ6bsdT/AL3fPTg4Nfo5+yfnybQXQ3HIzyBnk474B24+o25yQcfjRqHxX8Va
hj+zzZaPac/hguOw75HHpnkYyf1K/YN1c3OkM2o6v9svOOMDP3mHc4BA6fVh1Bz+q+Hvi5lvFuZS
y3LV0vZ/zXlZtPdNq2stNNdY39nG8TfE35RT6byT0T/mUbpt2dnum3+gPi7+yrayv7rUrWy+yWWn
Lj1x82f5A/TcAMjn+Cv/AIKCfGfVfjn+0X4jutNu/slp/wAJnx/31IDxk5zgfXjuDn+xj/gpL8cL
T4a/BHW7XTNV+x6r40xpunen/LT1PPQdSev+1z/FL4D8D3XiHxF4j8Z3Nr9stP8AkG+HPt+f7z9/
8cckcjlj+rLeXpD/ANKqH0vDG0vWH/pVQ1NO0PG7n7ZpNkf7voX4+8T1/PoMnOPWPC3hs+Hrc3P2
Y2l3rWO3Xlz3PThf0zySTseHvAzAWlra2/237Fj+0eB2L9+fx9cgZOa7dZ2tg1rodve6xqv+6OmW
9+PuqT65HJ2jPxv1yXn90f8AI90xra30fw8tp9qP+i8HPP8AxNPmkB4z/u8dsn3J9Z8L/A/x9rdv
b6oNKFppQ249vmOTzjrxn8OpGB9z/sa/8E7vFHjGa0
try this function :
public static String imageToString(Bitmap BitmapData) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
BitmapData.compress(Bitmap.CompressFormat.PNG, 100, bos);
byte[] byte_arr = bos.toByteArray();
String file = Base64.encodeToString(byte_arr, Base64.DEFAULT);
//appendLog(file);
return file;
}
There are some misunderstandings here. In your method you are receiving a bitmap (image) by parameter. If you want to pass it to base64 format, you are doing it right because base64 format is just a big String, as you can see in your return.
If the error is in your method and in de reverse process (parsing this String in Base64 to Bitmap), you can try this function:
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream .toByteArray();
to encode base64 from byte array use following method:
String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
Also, try to use this method to reverse the process of encode:
byte[] decodedString = android.util.Base64.decode(yourString, android.util.Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

Android base 64 encode string not showing actual image

Hello I am working with android image processing via base 64 encoding and decoding.I need to send an encoded base 64 string to server as a string . When I tried it in android side , I can able to decode it into original image.and my decoding and encoding are as follows
public void base(Bitmap bitmap)
{
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream .toByteArray();
String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
toimag(encoded);
String a=encoded.replaceAll("\\s+","");
Log.i("strrr",a);
}
public void toimag(String encodedImage)
{
byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
logo.setImageBitmap(decodedByte);
}
But I cant able to get the actual image using http://www.askapache.com/online-tools/base64-image-converter/ . It show only a part of my actual image. This is my base 64 string
iVBORw0KGgoAAAANSUhEUgAAAyAAAAJYCAIAAAAVFBUnAAAAA3NCSVQICAjb4U/gAAAgAElEQVR4
nKS9WbMsyXEm9n0emVVnu/vSDTTQQAMgOCMQHIDkiGM2Gs1QkkmU5kG/QX9QZjKZzYNMD3oZDheJ
Q2rEAUgNFwCNbqBB9N3vOacqw10P7h4RWXXORdOUuKjOk5WVGYsvny/hwf/p6SMAAMxMLE4AGAuA
QgJKAwFAxTCpkEaDAFCjKdTMbDZDHCoASUABoAhJkvktRKT96e/yP0UEANXMf4HCIiIiMpGUKkZC
CKE/QUCSC5Wkt5wksxWlFDOLvpj5K0jSCEDy1d54AALzl0FNVc2MBpJLUQAwMQPV1KrqoqpQq6aq
WmGqWlUXU1UtYIVVUzUutEW1mpmZclbYAqvgIlJV92bV9HozmZkqDFBKBRbYHqpSjKjEAlaKCoxi
xN7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kWKeB4mQmQXypZw8gxbEaGgfHSf3g4beNTMx7fpliC+u/b+mFQ48BAx80YGiiZjNWfD8S
gU+ptQavW+iHNo9j9sdSp+fJaEHxoAMHoz2iK79SEYqcoXahaVxmc/02hyI2oYf2VgPsLkpa8LMb
WEIWhUMdCYayCGMk+7YsnBIdBjNQCj93yhtcu6OFYSJBvjKFyuEU9xAmFGGoHIT136zywFiDSrsB
wCab+wB1f6tESJuWKi2EWhOa3WrDgEfRQNI7VYuImI15OGaAmgpliNB1zCG3+LQaYwzYS5Vj3slo
p1JTdIpCIqTl9AcFBXQDVBxjDdQ8uPYxItf8QAHpfkJaSYEmHUqtp6Ah+hzxUYC6
How can I resolve this issue ? Is there any problem with this encoded string ? Please help. Thanks in advance :)
It appears you are cutting and pasting from the logcat. logcat truncates long messages, so you should not rely on it for copying large pieces of data. You should save the base64 string out to a file and then try your validation using that file.
For Encode image to Base64
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();
String imageEncode = Base64.encodeToString(b,
Base64.DEFAULT);
For decode image
byte[] decodedByte = Base64.decode(imageEncode, 0);
Bitmap newBitmap = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
logo.setImageBitmap(newBitmap);

Categories