[英]app crashes when select image from gallery
I need to select from from gallery to implement filters on it . 我需要从图库中选择一个,以对其实施过滤器。 I open gallery in app with this code: 我使用以下代码在应用中打开图库:
var intent = Intent(Intent.ACTION_PICK)
intent.setType("image/*")
startActivityForResult(intent, PERMISSION_CODE)
Activity Result: 活动结果:
if (resultCode == Activity.RESULT_OK && requestCode == PERMISSION_CODE) {
var bitmap: Bitmap = BitmapUtils.getBitmapFromGallery(this, data?.data, 800, 800)
original_filter_bitmap.recycle()
final_bitmap.recycle()
filtered_bitmap.recycle()
original_filter_bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true)
final_bitmap = original_filter_bitmap.copy(Bitmap.Config.ARGB_8888, true)
filtered_bitmap = original_filter_bitmap.copy(Bitmap.Config.ARGB_8888, true)
image_preview.setImageBitmap(original_filter_bitmap)
bitmap.recycle()
// imageFiltersFragment.displayThumbNail(original_filter_bitmap)
}
Here is get from bitmap from gallery method: 这是从图库方法的位图获取的:
(Context context, Uri uri, int width, int height) {
String[] filepathcolumn = {MediaStore.Images.Media.DATA};
Cursor cursor = context.getContentResolver().query(uri, filepathcolumn, null, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filepathcolumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(picturePath, options);
options.inSampleSize = calculateInSampleSize(options, width, height);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(picturePath, options);
}
So gallery opens , i select image and when press to image app crushes. 因此,图库会打开,我选择图像,然后按图像应用程序崩溃。
Logcat: Logcat:
Caused by: java.lang.IllegalStateException: BitmapUtils.getBitmapFro…is, data?.data, 800, 800) must not be null
at com.example.sg772.textonimage.MainActivity.onActivityResult(MainActivity.kt:191)
line 191: var bitmap: Bitmap = BitmapUtils.getBitmapFromGallery(this, data?.data, 800, 800)
第191行: var bitmap: Bitmap = BitmapUtils.getBitmapFromGallery(this, data?.data, 800, 800)
data?.data
might be null. data?.data
可能为null。
data?.data?.let {
val bitmap = BitmapUtils.getBitmapFromGallery(this, it, 800, 800)
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.