所以我想从图库中选择一个图像,然后裁剪它:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), PHOTO_PICKED_WITH_DATA);
好的,选择照片,然后在ActivityResult上捕获它,然后裁剪它:
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(mAvatarUri, "image/*");
intent.putExtra("crop", true);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", ICON_SIZE);
intent.putExtra("outputY", ICON_SIZE);
intent.putExtra("scale", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mAvatarUri);
intent.putExtra("return-data", true);
startActivityForResult(intent, CROP_IMAGE);
现在,问题是当我想将其转换为字节然后在 XML 中发送它时......它不仅需要裁剪后的图像,还会占用整个图像本身......另外,我无法访问裁剪的图像 URI,它说找不到文件!嗯,似乎我裁剪的图像毕竟没有保存...
我该如何解决这个问题?
三星 ACE 2.3.4
在以下链接中检查此代码。
裁剪图像
它对我来说效果很好..
我不知道
你是如何获得这种裁剪图像的技术的。但是,对我来说,我总是使用这个库。它总是给我留下深刻的印象。从 android 2.1 一直到 3.2 工作(永远不要在 4.0 以后测试它)。
这是我的做法:
Intent cropIntent = new Intent(imageProcessActivity,
CropImage.class);
cropIntent.putExtra("image-path",
FileUtil.saveTempFile(ImageProcessActivity.processedBitmap, filename));
cropIntent.putExtra("scale", true);
imageProcessActivity.startActivityForResult(cropIntent, ImageProcessActivity.INTENT_CROP_CODE);
以下是捕获结果的方法:
if (requestCode == INTENT_CROP_CODE && resultCode == RESULT_OK) {
Bundle extras = intent.getExtras();
if (extras != null) {
Uri uri = null;
uri = (Uri) extras.get("imageCrop");
Bitmap bitmap = null;
try {
bitmap = ImageUtil.decodeFile(
new File(new URI(uri.toString())),
AppConstant.MAX_IMAGE_SIZE);
} catch (URISyntaxException e) {
e.printStackTrace();
}
processedBitmap = bitmap;
selectedImage.setImageBitmap(bitmap);
}
}