cats-oss / android-gpuimage

Android filters based on OpenGL (idea from GPUImage for iOS)
9k stars 2.27k forks source link

GPUImage.saveToPictures with preview blocks UI, up to 5 seconds when saving high resolution #131

Open chico opened 10 years ago

chico commented 10 years ago

Hi, I'm using GPUImage with preview and I've cloned the code from ActivityCamera.java from the sample into my own project. GPUImage works great except when the image is saved the UI gets blocked, specifically when GPUImage.saveToPictures is called. The screen goes black and it can take up to 5 seconds to save a 3264x2448 image on my Nexus 4.

Here's a code snippet from: https://gist.github.com/chico/7b374a28691de4a1f957

// in onCreate()
glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView);
mGPUImage = new GPUImage(this);        
mGPUImage.setGLSurfaceView(glSurfaceView);

// on user button click
mCamera.mCameraInstance.takePicture(null, null, new Camera.PictureCallback() {
    @Override
    public void onPictureTaken(byte[] data, final Camera camera) {

        camera.startPreview();

        Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);

        // GPUImage.saveToPictures blocks UI and view goes black for up to 5 seconds when saving high resolution picture
        mGPUImage.saveToPictures(bitmap, "GPUImage", null);
    }
});
chico commented 9 years ago

I've had to use RenderScript instead of mGPUImage.saveToPictures so that the main UI isn't blocked. Luckily RSImage (https://github.com/fuzz-productions/RSImage), a project based off GPUImage with ready made renderscripts, made this possible. I've found that RenderScript isn't any quicker at processing the image but at least it can be done in an async task.

jibinjoseph commented 8 years ago

So your problem solved?? me too trying to fix this issue?Any help please?

chico commented 8 years ago

I'm afraid saving high resolution pictures with decent performance and consistent on all Android devices is actually quite hard. I had to outsource the work to someone who is specialised in this type of work to solve this issue. Sorry I can't be of more help.

jibinjoseph commented 8 years ago

Okay.Thank You :)

mPixster commented 6 years ago

i have a save issue. when i saveTopictures method call get UI block.. how to solve this issue