Answer the question
In order to leave comments, you need to log in
Ways to convert image to base64 in java?
There is a certain ImageView in which the image lies. It is required to transfer the image to the server using the POST method. On the server, the data is processed by a php script.
img = photoHolder.getDrawable();
BitmapDrawable bitmapDrawable = ((BitmapDrawable) img);
Bitmap bitmap = bitmapDrawable .getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
imageInByte = stream.toByteArray();
String img = new String(Base64.encode(imageInByte, Base64.DEFAULT));
String myParams = "img="+img;
$img1 = base64_decode($img);
$filename = "img/asd.jpg";
file_put_contents($filename, $img1);
Answer the question
In order to leave comments, you need to log in
So encode the same image on the server and compare, maybe the problem is just in the encoding, not in the one that is base64, but in the one in which the bytes are presented in the request - UTF-8 or 1251, start with something simpler, better with plain text files of several bytes.
Actually, your question is...
- So, now show me how you learned to turn off the computer ... Yes, not with RESET, but with the mouse!
- Good! *picks up mouse from table and clicks on RESET*
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question