当我在 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 intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
代替
intent.setAction(Intent.ACTION_GET_CONTENT);
关于java - 在 Sony z2 上从图库中选取图像时出现 IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34363365/