Android 检查使用edmodo裁剪器库选择的文件是否为图像
在使用内置CropImageActivity选择图像时,选择器会显示从外部应用程序WPS Office中为我的案例选择任何类型文件的选项。因此,当我选择一个pdf文件时,比如说,onSetImageUriComplete不会导致任何错误Android 检查使用edmodo裁剪器库选择的文件是否为图像,android,image,cropper,Android,Image,Cropper,在使用内置CropImageActivity选择图像时,选择器会显示从外部应用程序WPS Office中为我的案例选择任何类型文件的选项。因此,当我选择一个pdf文件时,比如说,onSetImageUriComplete不会导致任何错误 @Override public void onSetImageUriComplete(CropImageView cropImageView, Uri uri, Exception error) { progressView.setVi
@Override
public void onSetImageUriComplete(CropImageView cropImageView, Uri uri, Exception error) {
progressView.setVisibility(View.INVISIBLE);
if (error != null) {
Log.e(LOG_TAG, "Failed to load image for cropping", error);
AndroidUtils.showToast("Unable to upload", this);
finish();
}
}
对于这种情况,错误不为空。所以,UI中没有显示任何内容,我也无法知道它是否是图像
我尝试从URI检查扩展,但在一些模型中,对于我的情况,URI不一定包含扩展
我还尝试将uri加载到文件中,然后使用以下代码进行检查:
public static boolean isImage(File file) {
if (file == null || !file.exists()) {
return false;
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file.getPath(), options);
return options.outWidth != -1 && options.outHeight != -1;
}
但是,对于1加X,它再次返回false。是否有其他不占用资源的方法来检查获取的文件是否为图像
所以,UI中没有显示任何内容,我也无法知道它是否是图像
调用,传入Uri。如果MIME类型以image/开头,则它是一个映像。您的意思是:字符串mimeType=context.getContentResolver.getTypeimageUri;。这将为me@AvinashGupta:真的吗?Uri的值是多少?file:///storage/emulated/0/DCIM/Camera/IMG_20170122_162307.jpgOK,我认为getType将处理文件方案和内容方案。使用MimeTypeMap获取MIME类型。如果getType适用于内容方案,那么可能我得到了解决方案。我提到的上述方法已经适用于文件方案。谢谢我会为内容确认这一点