在相机覆盖范围内获取图像

时间:2015-09-14 13:13:37

标签: android android-camera android-imageview surfaceview camera-overlay

enter image description here

我目前在我的自定义相机上有相机覆盖(Imageview)。我有一切工作。现在只需要在叠加层中获取图像。我该怎么做呢做了很多研究,但没有找到有效的方法。

P.S。如果你给我负面积分,请说明原因。

    private Camera.PictureCallback mJPEGPictureCallback = new Camera.PictureCallback() {

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        CameraConfigurationUtils.releaseCamera();
        ProcessImageAsyncTask processImageAsyncTask = new ProcessImageAsyncTask(CameraActivity.this);
        processImageAsyncTask.setTaskCompletedListener(new ProcessImageAsyncTask.OnImageProcessingCompletedInterface() {
            @Override
            public void onImageProcessComplete(Bitmap bitmap) {
                if (mProgressDialog != null && mProgressDialog.isShowing()) {
                    mProgressDialog.dismiss();
                }
                enablePreviewMode();
                bitmap = Bitmap.createBitmap(bitmap, transparentView.getHeight(), transparentView.getLeft(), transparentView.getWidth(), transparentView.getHeight());
                cameraPreviewImage.setImageBitmap(bitmap);
                File pictureFile = CameraImageUtils.getOutputMediaFile();
                if (pictureFile == null) {
                    Log.d(TAG, "Error creating media file, check storage permissions: ");
                    return;
                }
                try {
                    FileOutputStream fos = new FileOutputStream(pictureFile);
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 70, fos);
                    fos.flush();
                    fos.close();


 Toast.makeText(getApplicationContext(), "Picture size in " + ((float) (pictureFile.length()) / (1024 * 1024)) + " mb", Toast.LENGTH_SHORT).show();
                    } catch (FileNotFoundException e) {
                        Log.d(TAG, "File not found: " + e.getMessage());
                    } catch (IOException e) {
                        Log.d(TAG, "Error accessing file: " + e.getMessage());
                    }
                }
            });
            processImageAsyncTask.execute(data);
        }
    };

0 个答案:

没有答案