Извлечение растрового изображения из uri
Я включил опцию "share by myApp". Я вставил следующий код в класс принимающей активности.
// Get the intent that started this activity
Intent intent = getIntent();
Uri data = intent.getData();
// Figure out what to do based on the intent type
if (intent.getType().indexOf("image/") != -1) {
// Handle intents with image data ...
}
Каков следующий шаг для извлечения растрового изображения.
Ответы
Ответ 1
Как вы уже получили Uri. Теперь вам нужно передать Uri в getBitmap()
, чтобы получить растровое изображение и использовать это растровое изображение.
Uri imageUri = intent.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),imageUri);
Imageview my_img_view = (Imageview ) findViewById (R.id.my_img_view);
my_img_view.setImageBitmap(bitmap);
Ответ 2
Для получения растрового изображения из uri,
Bitmap mBitmap = Media.getBitmap(this.getContentResolver(), uri);
Надеюсь, это поможет вам.
Ответ 3
Retrive bitmap from uri.....
public static Bitmap decodeUriToBitmap(Context mContext, Uri sendUri) {
Bitmap getBitmap = null;
try {
InputStream image_stream;
try {
image_stream = mContext.getContentResolver().openInputStream(sendUri);
getBitmap = BitmapFactory.decodeStream(image_stream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
return getBitmap;
}
Ответ 4
Это работа для меня
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
Uri imageUri = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
}
}
Ответ 5
Пожалуйста, предпочитайте эту ссылку.
Это то, что вы ищете
Как получить Bitmap из Uri?
Попробуй, это сработает для меня:
public static Bitmap getBitmapFromURL(String src) {
try {
System.out.printf("src", src);
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
System.out.printf("Bitmap", "returned");
myBitmap = Bitmap.createScaledBitmap(myBitmap, 100, 100, false);//This is only if u want to set the image size.
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
System.out.printf("Exception", e.getMessage());
return null;
}