将设备库中的大尺寸图像添加到我的应用程序时,我的应用程序崩溃了。我经历了一些解决方案,如调整大小、缩放等,但没有成功。
当我从图库中选择图像时,执行以下代码部分
protected void onActivityResult(int requestCode, int resultCode,
Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case REQ_CODE_PICK_IMAGE:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
//Convert Bitmap to Byte Array:-
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
yourSelectedImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
//Pass byte array into intent:-
Intent intent = new Intent(UserAccount.this,RetrieveImage.class);
intent.putExtra("picture", byteArray);
startActivity(intent);
} } }
检索图像.java
Bundle extras = getIntent().getExtras();
byte[] byteArray = extras.getByteArray("picture");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView img = (ImageView) findViewById(R.id.imageView1);
img.setImageBitmap(bmp);
我怎么解决这个问题。