在 Sony z2 上从图库中选取图像时出现 IllegalArgumentException
IllegalArgumentException while picking image from gallery on Sony z2
当我在 Sony Z2 上 运行 脚本时它抛出这个异常,虽然它 运行 在 Samsung s4 中很顺利:
Caused by: java.lang.IllegalArgumentException: filename cannot be
null
at (MyDetailsPage.java:274)
这是我的程序,java:274 在外部代码中:
public Bitmap decodeScaledDownBitmapFromDatabase(String imagePath,int requiredHeight,int requiredWidth){
final BitmapFactory.Options options=new BitmapFactory.Options();
options.inJustDecodeBounds=true;
Bitmap bitmap=BitmapFactory.decodeFile(imagePath, options);
Matrix matrix;
options.inSampleSize=calculateInputImageSize(options, requiredHeight, requiredWidth);
options.inJustDecodeBounds=false;
bitmap =BitmapFactory.decodeFile(imagePath, options);
int angel=0;
try{
java : 276 ExifInterface exifInterface=new ExifInterface(imagePath);
int orientation=exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_UNDEFINED);
if (orientation==ExifInterface.ORIENTATION_ROTATE_90){
angel=90;
}
else if(orientation==ExifInterface.ORIENTATION_ROTATE_180){
angel=180;
}
else if (orientation==ExifInterface.ORIENTATION_ROTATE_270){
angel=270;
}
}
catch (IOException e){
Toast.makeText(getApplicationContext(),"Image could not be selected",Toast.LENGTH_LONG).show();
}
matrix=new Matrix();
matrix.postRotate(angel);
Bitmap readyBitmap=Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
return readyBitmap;
}
好吧,这似乎很荒谬,只是写下答案,希望能对某人有所帮助。它如何影响整个代码真的很奇怪。
调用意图时我使用
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
而不是
intent.setAction(Intent.ACTION_GET_CONTENT);
当我在 Sony Z2 上 运行 脚本时它抛出这个异常,虽然它 运行 在 Samsung s4 中很顺利:
Caused by: java.lang.IllegalArgumentException: filename cannot be null
at (MyDetailsPage.java:274)
这是我的程序,java:274 在外部代码中:
public Bitmap decodeScaledDownBitmapFromDatabase(String imagePath,int requiredHeight,int requiredWidth){
final BitmapFactory.Options options=new BitmapFactory.Options();
options.inJustDecodeBounds=true;
Bitmap bitmap=BitmapFactory.decodeFile(imagePath, options);
Matrix matrix;
options.inSampleSize=calculateInputImageSize(options, requiredHeight, requiredWidth);
options.inJustDecodeBounds=false;
bitmap =BitmapFactory.decodeFile(imagePath, options);
int angel=0;
try{
java : 276 ExifInterface exifInterface=new ExifInterface(imagePath);
int orientation=exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_UNDEFINED);
if (orientation==ExifInterface.ORIENTATION_ROTATE_90){
angel=90;
}
else if(orientation==ExifInterface.ORIENTATION_ROTATE_180){
angel=180;
}
else if (orientation==ExifInterface.ORIENTATION_ROTATE_270){
angel=270;
}
}
catch (IOException e){
Toast.makeText(getApplicationContext(),"Image could not be selected",Toast.LENGTH_LONG).show();
}
matrix=new Matrix();
matrix.postRotate(angel);
Bitmap readyBitmap=Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
return readyBitmap;
}
好吧,这似乎很荒谬,只是写下答案,希望能对某人有所帮助。它如何影响整个代码真的很奇怪。 调用意图时我使用
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
而不是
intent.setAction(Intent.ACTION_GET_CONTENT);