在surfaceView android上裁剪图像



我使用的是SurfaceHolder。回调和相机。在拍摄图像后,我想裁剪该图像,然后将其保存到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)格式。实际上我正在研究如何制作这个部分,这就是为什么我遇到你的问题。

这里的重点是,你如何将图片传递给裁剪方法,你应该研究一下。

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");
    }
}

最新更新