Android Convert Image to Base64 String or Base64 String to ...
Android Convert Image to Base64 String or Base64 String to
Image
Create new android studio project
Add an image in res/drawable folder. This is the image that we will convert. See below
screenshot we have added an image with name logo.png.
Now add following code in respectively files.
acitivity_main.xml
MainActivity.java
package com.base64example;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Base64;
import android.widget.ImageView;
import java.io.ByteArrayOutputStream;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView image =(ImageView)findViewById(R.id.image);
//encode image to base64 string
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
press(pressFormat.JPEG, 100, baos);
byte[] imageBytes = baos.toByteArray();
String imageString = Base64.encodeToString(imageBytes, Base64.DEFAULT);
System.out.println("Start file base64");
System.out.println(imageString);
//decode base64 string to image
imageBytes = Base64.decode(imageString, Base64.DEFAULT);
Bitmap decodedImage = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
image.setImageBitmap(decodedImage); }}
Run the project.
We are converting the image to base64 string and then converting back to bitmap and
finally showing it in ImageView.
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- converting image to pdf in java
- convert image to base64 react js
- 1 5 https 21z2f6
- conversion of dicom image in to jpeg bmp and png image format
- js convert image to base64
- decode base64 to image javascript
- android convert image to base64
- android convert image to base64 string or base64 string to
- encrypt and decrypt image using vigenere cipher
- title dyndoc — convert dynamic markdown document
Related searches
- convert image to base64 js
- android convert string to int
- python image to base64 string
- powershell convert image to base64 string
- python base64 string to bytes
- convert image to base64 string
- image to base64 converter
- base64 string to image online
- convert base64 string to file
- convert base64 string to pdf
- convert base64 string to string
- image to base64 converter online