与华为合作的Android拾取和裁剪图像
在我的应用程序中,我让用户选择一幅图像,然后进行裁剪。在此之后,图像被设置为imageView 我的解决方案没有任何问题,直到昨天我收到两个使用华为智能手机的人的信息,他们都有同样的问题。他们总是收到一条消息“加载图像失败…”,并且没有图像设置到imageView 在调试过程中,我发现对于裁剪意图,data.getData()在onActivityResult中为null 我尝试了很多不同的方法来挑选和裁剪图像,所有这些方法都对我有用,但对华为智能手机没有。我没有主意了,可能需要一些帮助 代码如下:与华为合作的Android拾取和裁剪图像,android,image,crop,huawei-mobile-services,Android,Image,Crop,Huawei Mobile Services,在我的应用程序中,我让用户选择一幅图像,然后进行裁剪。在此之后,图像被设置为imageView 我的解决方案没有任何问题,直到昨天我收到两个使用华为智能手机的人的信息,他们都有同样的问题。他们总是收到一条消息“加载图像失败…”,并且没有图像设置到imageView 在调试过程中,我发现对于裁剪意图,data.getData()在onActivityResult中为null 我尝试了很多不同的方法来挑选和裁剪图像,所有这些方法都对我有用,但对华为智能手机没有。我没有主意了,可能需要一些帮助 代码如
public void onClick(View v){
Permissions.verifyStoragePermissions(this);
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
&& null != data) {
Uri uri = data.getData();
this.performCrop(uri);
} else if (requestCode == RESULT_CROP_IMG) {
if (data != null) {
ImageView imgView =
(ImageView) findViewById(R.id.imageView_my_profile);
imgView.setImageURI(data.getData());
}
}
} catch (Exception e) {
Toast.makeText(this, getString(R.string.global_default_error), Toast.LENGTH_LONG)
.show();
}
}
private void performCrop(Uri picUri) {
try {
ImageView imgView = (ImageView) findViewById(R.id.imageView_my_profile);
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", imgView.getWidth());
cropIntent.putExtra("aspectY", imgView.getHeight());
cropIntent.putExtra("outputX", imgView.getWidth());
cropIntent.putExtra("outputY", imgView.getHeight());
String folder_main = "Test";
File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), folder_main);
f.mkdirs();
f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString()+"/Test/profilepic" + System.currentTimeMillis() +".jpg");
Uri newUri = Uri.fromFile(f);
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, newUri);
startActivityForResult(cropIntent, RESULT_CROP_IMG);
}
catch (ActivityNotFoundException anfe) {
ImageView imgView = (ImageView) findViewById(R.id.imageView_my_profile);
imgView.setImageURI(picUri);
}
}
. 有很多。请使用一个。非常感谢,它现在与其中一个库一起工作=)@babaum你能分享这个库链接吗