Storing image in sharedpreference

mHomePage.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Intent intent = new Intent();

intent.setAction(Intent.ACTION_PICK);

intent.setType("image/*");

startActivityForResult(intent, REQUEST_CODE);

}

});

mHomePage.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Intent galleryIntent = new Intent(Intent.ACTION_PICK,

android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

startActivityForResult(galleryIntent, RESULT_LOAD);

}

});

return rootView;

}

public void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

// When an Image is picked

if (requestCode == RESULT_LOAD && resultCode == RESULT_OK) {

Uri resultUri = data.getData();

CropImage.activity(resultUri)

.start(getActivity());

}

if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {

CropImage.ActivityResult result = CropImage.getActivityResult(data);

Uri uri = result.getUri();

Bitmap realImage = BitmapFactory.decodeStream(uri);

ByteArrayOutputStream baos = new ByteArrayOutputStream();

realImage.compress(Bitmap.CompressFormat.JPEG, 100, baos);

byte[] b = baos.toByteArray();

String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);

SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(getActivity());

SharedPreferences.Editor edit=shre.edit();

edit.putString("image_data",encodedImage);

edit.commit();

}

Trying to store image in sharedpreference by encoding but im new...

Read More »

By: StackOverFlow - Wednesday, 7 November

Related Posts