![](/img/trans.png)
[英]How can I download my bitmap to gallery from url Android Studio
[英]How can I bitmap my gallery image in android studio
大家好,我正在尝试对我的图像进行位图处理,但是每次我从我的图库中选择任何图像时,它都会给我一个空位图。 请帮忙
public void start(View view) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, Gallery_Intent);
}
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uri = data.getData();
imageView.setImageURI(uri);
Uri pickedImage = data.getData();
// Let's read picked image path using content resolver
String[] filePath = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(pickedImage, filePath, null, null, null);
cursor.moveToFirst();
String imagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(imagePath, options);
if (bitmap == null)
Toast.makeText(MainActivity.this, "failed1", Toast.LENGTH_SHORT).show();
}
您可以使用 Picasso 或 Glide 更轻松地获得图像位图,示例是使用 Picasso
Bitmap bitmap = Picasso.get().load(uri).get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.