簡體   English   中英

在SurfaceView Android上裁剪圖像

[英]Crop an image on surfaceView android

我正在使用SurfaceHolder.Callback和Camera.PictureCallback在我的活動中打開Camera拍攝圖像后,我想裁剪該圖像,然后將其保存到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");

    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM