nam*_*hu1 7 java android image crop android-layout
我需要从Android手机画廊裁剪一张照片,然后进行编辑.照片的原始尺寸为3264*2448,在我的尺寸为1280*720的屏幕上显示为缩小的图像.当我裁剪它时,我得到的图像大小为185*139.
我用于裁剪的代码是
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, PIC_CROP);
Run Code Online (Sandbox Code Playgroud)
当我在imageView中显示裁剪的图像时,它显示为更小的图像.
我应该裁剪原始大小的图像而不是缩小版本.你们有没有人可以指导我如何做到这一点?
Aka*_*ore 13
请试试这个,我知道为时已晚,但可能会对某人有所帮助.
private void performCrop() {
try {
//call the standard crop action intent (the user device may not support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP");
//indicate image type and Uri
cropIntent.setDataAndType(mImageCaptureUri, "image/*");
//set crop properties
cropIntent.putExtra("crop", "true");
//indicate aspect of desired crop
cropIntent.putExtra("aspectX", 4);
cropIntent.putExtra("aspectY", 3);
//indicate output X and Y
cropIntent.putExtra("outputX", 800);
cropIntent.putExtra("outputY", 800);
File f = new File(Environment.getExternalStorageDirectory(),
"/temporary_holder.jpg");
try {
f.createNewFile();
} catch (IOException ex) {
Log.e("io", ex.getMessage());
}
uri = Uri.fromFile(f);
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(cropIntent, PIC_CROP);
} //respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
//display an error message
String errorMessage = "Your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
Run Code Online (Sandbox Code Playgroud)
让你的onActivityResult像这样: -
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PIC_CROP) {
String filePath = Environment.getExternalStorageDirectory()
+ "/temporary_holder.jpg";
thumbnail = BitmapFactory.decodeFile(filePath);
//thumbnail = BitmapFactory.decodeFile(filePath);
// Log.i("",String.valueOf(thumbnail.getHeight()));
ImageView image = (ImageView) findViewById(R.id.pestImage);
image.setImageBitmap(thumbnail);
}
}
Run Code Online (Sandbox Code Playgroud)
首先,您应该意识到不能依赖裁剪意图来实现跨设备兼容性。(任何 OEM 都可以用自己的版本替换库存相机/图库应用程序)。除此之外,我认为您错过了一些应该符合意图并给您带来预期效果的额外内容。
// width & height are your desired width/height for the cropped result
cropIntent.putExtra("outputX", width);
cropIntent.putExtra("outputY", height);
cropIntent.putExtra("aspectX", width);
cropIntent.putExtra("aspectY", height);
cropIntent.putExtra("scaleUpIfNeeded", true);
Run Code Online (Sandbox Code Playgroud)
尝试将这些添加到您的意图中,看看结果如何。
| 归档时间: |
|
| 查看次数: |
4910 次 |
| 最近记录: |