Search in sources :

Example 1 with OnPictureSavedListener

use of jp.co.cyberagent.android.gpuimage.GPUImage.OnPictureSavedListener in project android-gpuimage by CyberAgent.

the class ActivityCamera method takePicture.

private void takePicture() {
    // TODO get a size that is about the size of the screen
    Camera.Parameters params = mCamera.mCameraInstance.getParameters();
    params.setRotation(90);
    mCamera.mCameraInstance.setParameters(params);
    for (Camera.Size size : params.getSupportedPictureSizes()) {
        Log.i("ASDF", "Supported: " + size.width + "x" + size.height);
    }
    mCamera.mCameraInstance.takePicture(null, null, new Camera.PictureCallback() {

        @Override
        public void onPictureTaken(byte[] data, final Camera camera) {
            final File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
            if (pictureFile == null) {
                Log.d("ASDF", "Error creating media file, check storage permissions");
                return;
            }
            try {
                FileOutputStream fos = new FileOutputStream(pictureFile);
                fos.write(data);
                fos.close();
            } catch (FileNotFoundException e) {
                Log.d("ASDF", "File not found: " + e.getMessage());
            } catch (IOException e) {
                Log.d("ASDF", "Error accessing file: " + e.getMessage());
            }
            data = null;
            Bitmap bitmap = BitmapFactory.decodeFile(pictureFile.getAbsolutePath());
            // mGPUImage.setImage(bitmap);
            final GLSurfaceView view = (GLSurfaceView) findViewById(R.id.surfaceView);
            view.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
            mGPUImage.saveToPictures(bitmap, "GPUImage", System.currentTimeMillis() + ".jpg", new OnPictureSavedListener() {

                @Override
                public void onPictureSaved(final Uri uri) {
                    pictureFile.delete();
                    camera.startPreview();
                    view.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
                }
            });
        }
    });
}
Also used : Parameters(android.hardware.Camera.Parameters) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) OnPictureSavedListener(jp.co.cyberagent.android.gpuimage.GPUImage.OnPictureSavedListener) GLSurfaceView(android.opengl.GLSurfaceView) Uri(android.net.Uri) Bitmap(android.graphics.Bitmap) FileOutputStream(java.io.FileOutputStream) Camera(android.hardware.Camera) File(java.io.File)

Aggregations

Bitmap (android.graphics.Bitmap)1 Camera (android.hardware.Camera)1 Parameters (android.hardware.Camera.Parameters)1 Uri (android.net.Uri)1 GLSurfaceView (android.opengl.GLSurfaceView)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OnPictureSavedListener (jp.co.cyberagent.android.gpuimage.GPUImage.OnPictureSavedListener)1