Graphics Image Base64

//on onCreate


}
private static final String STATE_IMAGE_URI = "STATE_IMAGE_URI";
private Uri imageUri;
public void onSaveInstanceState(Bundle state) {
super.onSaveInstanceState(state);
if (imageUri != null ) {
state.putParcelable(STATE_IMAGE_URI, imageUri);
}
}
public void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);
if(state == null || !state.containsKey(STATE_IMAGE_URI)) return;
setImage((Uri)state.getParcelable(STATE_IMAGE_URI));
}
private static final int IMAGE_REQUEST_CODE = 9;
private void chooseImage() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select picture"), IMAGE_REQUEST_CODE);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode != IMAGE_REQUEST_CODE) {
return;
}
if (resultCode != Activity.RESULT_OK) {
return;
}
setImage(data.getData());
}
private void setImage(Uri uri) {
imageUri = uri;
imageview1.setImageURI(uri);
i = 1; //key on list
}
private void nothing() {


//ImageView
chooseImage();

//On Button To image base64

imageview1.buildDrawingCache();
Bitmap bitmap = imageview1.getDrawingCache(); java.io.ByteArrayOutputStream stream=new java.io.ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream);
byte[] imageByteArray=stream.toByteArray();
String img_str = Base64.encodeToString(imageByteArray, 0);



//Base64 To Image
byte[] decodedString = Base64.decode(BASE64STRINGVARIABLE, Base64.DEFAULT); Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
imageview1.setImageBitmap(decodedByte);

Komentar

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

TextInputLayout in Sketchware

How to find and​ highlight a word in a text field in Sketchware?

A Flash Light App in Sketchware

How to enable download in webview in Sketchware apps?

Intent - Open File By Type

Code for implementing Notifications in Sketchware

How to share an image from Drawable folder?

ActionBar back button

Animation Transtition Animation