我正在处理一个应用程序。我在该应用程序中有一个上传按钮。当我点击上传按钮移动图库打开然后我选择图像并将其上传到ImageView。我的应用程序在少数移动设备上工作,但是当我在三星Galexy Note3上尝试时,应用程序在将图像上传到imageview时没有响应。请帮帮我。
上传代码按钮:
upload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, REQ_CODE_PICK_IMAGE1);
}
});
onActivityResult上的代码:
switch (requestCode) {
case REQ_CODE_PICK_IMAGE1:
if (resultCode == RESULT_OK) {
Uri selectedImage = data.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 picturePath = cursor.getString(columnIndex);
cursor.close();
this.path1 = picturePath;
// iv1.setImageBitmap(BitmapFactory.decodeFile(picturePath));
try {
iv1.setImageBitmap(decodeBitmap(selectedImage,
EyeMatch.this));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
iv1.setScaleType(ScaleType.FIT_XY);
break;
}
位图代码decodeBitmap:
public static Bitmap decodeBitmap(Uri selectedImage, Context context)
throws FileNotFoundException {
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(context.getContentResolver()
.openInputStream(selectedImage), null, o);
final int REQUIRED_SIZE = 100;
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while (true) {
if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE) {
break;
}
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeStream(context.getContentResolver()
.openInputStream(selectedImage), null, o2);
}