如何解决如何从外部 Intent 裁剪图像
TLDR 因此,当我尝试在我的应用程序中共享来自另一个应用程序的图像时,我想使用所选图像打开裁剪意图
在我的应用中,可以通过共享意图共享来自另一个应用的图像。 所以例如您可以直接在我的应用中分享来自 Reddit 的图片。 它工作得很好,但我想添加一个功能,您可以裁剪图像,因为有些图像的上方和下方都有巨大的黑屏(可能因为它们只是屏幕截图)。
我可以裁剪从图库拍摄的图像。 但是,当我从外部意图使用共享时,图像不会保存到我的手机中,因此我无法打开它并对其进行裁剪。
private void getData() {
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if (type.startsWith("image/")) {
handleSendImage(intent);
}
if (type.startsWith("text/")) {
handleSendText(intent);
}
}
}
void handleSendImage(Intent intent) {
imageUrl = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUrl != null) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUrl),null,options);
} catch (FileNotFoundException e) {
e.printstacktrace();
}
choose_image_iv.setColorFilter(0);
Picasso.get().load(imageUrl).fit().into(choose_image_iv);
try {
Bitmap img = MediaStore.Images.Media.getBitmap(getContentResolver(),imageUrl);
if (img == null) return;
int w = img.getWidth();
int h = img.getHeight();
rat = (double) w / (double) (h);
} catch (IOException e) {
e.printstacktrace();
}
if (rat == 0.0) {
rat = 1.0;
}
rightNavButton.setEnabled(true);
rightNavButton.setimageResource(R.drawable.baseline_navigate_next_black_24dp);
rightNavButton.setColorFilter(ContextCompat.getColor(ShareFromOutsideActivity.this,R.color.AppColor));
titleView.setText(R.string.choose_category);
post_text_text_tv.requestFocus();
}else {
new SweetAlertDialog(this,SweetAlertDialog.ERROR_TYPE)
.setTitleText("Mit diesem Bild scheint etwas nicht zu stimmen. Probier ein anderes").show();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。