【发布时间】:2013-05-19 19:04:39
【问题描述】:
我正在使用 SurfaceHolder.Callback 和 Camera.PictureCallback 在我的活动中打开相机拍摄图像后,我想裁剪该图像,然后将其保存到 SD 卡。我找到了许多通过意图相机进行裁剪的解决方案,但没有找到符合我的要求的任何解决方案。
如果有人帮助我,我将不胜感激。
提前致谢。
【问题讨论】:
我正在使用 SurfaceHolder.Callback 和 Camera.PictureCallback 在我的活动中打开相机拍摄图像后,我想裁剪该图像,然后将其保存到 SD 卡。我找到了许多通过意图相机进行裁剪的解决方案,但没有找到符合我的要求的任何解决方案。
如果有人帮助我,我将不胜感激。
提前致谢。
【问题讨论】:
你应该实现 Camera.PreviewCallback 而不是 Camera.PictureCallback,
通过使用接口实现方法:
public void onPreviewFrame(byte[] data, Camera camera) {
if (shutterEnabled){
shutterEnabled = false;
// Process data
// Put it on a Bitmap
// Send it to cropImage
// -----
}
}
请注意,如果您没有设置相机参数 setPreviewFormat,viewPreviewFrame 上的图片将以 YUV (NV21) 格式到达。 实际上我正在寻找如何制作这部分,这就是我碰到你的问题的原因。
这里的重点,你打算如何将图片传递给crop方法,你应该研究一下。
shutterEnabled 标志,它是从“监视”该事件的侦听器启用的。
private void cropImage( picture){
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picture, "image/*");
cropIntent.putExtra("aspectX",0);
cropIntent.putExtra("aspectY",0);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, CAMERA_CROP_CODE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (resultCode == RESULT_OK && requestCode == CAMERA_CROP_CODE){
Bitmap bmp = (Bitmap)data.getExtras().get("data");
}
}
【讨论】: