vxh.viet
5/12/2016 - 7:43 AM

Common Bitmap, Uri, Path conversion

Common Bitmap, Uri, Path conversion

Source: StackOverflow, StackOverflow

Answer:

  • Convert Uri to Bitmap:

Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);

  • Get image path from Uri:
public Uri getImageUri(Context inContext, Bitmap inImage) {
  ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
  String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
  return Uri.parse(path);
} 
  • Get Uri from path:

Uri.fromFile(new File(path)