0

I am developing one project which is used to apply some effects on the image which will be selected from gallery or captured through camera.

I have used the GPUImageView library for applying different effects on the images and also implemented the seekbar for increasing and decreasing the effects. Everything is working fine.

The problem is that now i want to save that effects applied image into sdcard. I have written the code for it and its working successfully but the image is saved is remained black. Whenever i check the image from the sdcard it does not show the modified image except black screen.

I do not know why its showing black image.

Here is the code where i have made the GPUImageView as drawingcachedenabled to true and saving it as image.

mGPUImageView.setDrawingCacheEnabled(true);
Bitmap bitmap = mGPUImageView.getDrawingCache();
String path = Environment.getExternalStorageDirectory()
                    .getAbsolutePath();
File fil = new File(path + "/MyPics");
fil.mkdir();
Random rand = new Random();
int aa = rand.nextInt();
String filename = "Photo" + aa+".jpg";
File newImg = new File(fil, filename);
    try {
        FileOutputStream out = new FileOutputStream(newImg);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
    } catch (Exception e) {

}
    Toast.makeText(this,"File Saved at Path---->" + newImg.getAbsolutePath(),
                    Toast.LENGTH_LONG).show();
            mGPUImageView.setDrawingCacheEnabled(false);

Please help me to solve the issue.

GrIsHu
  • 29,068
  • 10
  • 64
  • 102
  • You can directly get effects Bitmap from the **GpuImage.getBitmapWithFilterApplied(final Bitmap bitmap)** rather than get it from the SurfaceView.. – kalyan pvs Mar 26 '14 at 09:59
  • `GLSurfaceView` is quite different from a normal `View`. So you can not get contents of `GLSurfaceView` by using `getDrawingcache()` as everything is rendered on `GLSurfaceView` using GPU. and [this](http://stackoverflow.com/questions/21753519/display-black-screen-while-capture-screenshot-of-glsurfaceview/21756336#21756336) answer may help you... – Gopal Gopi Mar 26 '14 at 10:00
  • Why are you not using `saveToPictures()` method of `GPUImageView.java`?? Is there any problem?? – user370305 Mar 26 '14 at 10:01
  • @user370305 I already tried that but it doesn't work for me. – GrIsHu Mar 26 '14 at 10:02
  • What are the problems? Did you seen any log from `GPUImageView` in logcat? – user370305 Mar 26 '14 at 10:03
  • I did not get any issues. But its asking for the Listener `OnPictureSavedListener` implementation and the listener wants Uri of the image Which is not possible to pass for me. – GrIsHu Mar 26 '14 at 10:04
  • Ok, call `public Bitmap getBitmapWithFilterApplied()` this method of `GPUImage.java`. It will return effect applied current bitmap image and using Bitmap Factory store in Sdcard. – user370305 Mar 26 '14 at 10:07
  • I guess you have added `GPUImage` library source into your project. – user370305 Mar 26 '14 at 10:09
  • Yes, Its added @user370305 – GrIsHu Mar 26 '14 at 10:09
  • 1
    OK, try my above comment and let me know what happen. Because `GPUImage` Library code tested and working fine. – user370305 Mar 26 '14 at 10:10
  • But i have used `GPUImageView` not `GPUImage` class. – GrIsHu Mar 26 '14 at 10:11
  • @GrIsHu I dont Know how to use GPUImageView but with GPUImage its working fine and easy too.. – kalyan pvs Mar 26 '14 at 10:13
  • @kalyanpvs Please can you show me how you have used it ? – GrIsHu Mar 26 '14 at 10:16
  • @GrIsHu ok..wait i will post.. – kalyan pvs Mar 26 '14 at 10:18
  • Thank you all I have resolved my issue by help of @user370305 . Thanks for your time and suggestions. – GrIsHu Mar 26 '14 at 11:26

2 Answers2

1

You can Create object for GPUImage and Apply your filter..

    final GPUImage mGpuImage = new GPUImage(getApplicationContext());
    mGpuImage.setFilter(new GPUImageSharpenFilter());//Your filter here
    Bitmap effectsBItamap=mGpuImage.getBitmapWithFilterApplied(your bitmap);
kalyan pvs
  • 14,486
  • 4
  • 41
  • 59
1

I have resolved my issue by using the saveToPictures() method of GPUImageView.java. I simply converted the File newImg into the Uri and passed it to the Listener of OnPictureSavedListener class's onPictureSaved method as below:

        mGPUImageView.setDrawingCacheEnabled(true);
        File fil = new File(path);
        fil.mkdir();
        Random rand = new Random();
        int aa = rand.nextInt();

        mGPUImageView.setDrawingCacheEnabled(false);
         mGPUImageView.saveToPictures("MyPics", "Photo"+aa+".jpg", picSaveListener);
        picSaveListener.onPictureSaved(Uri.fromFile(newImg)); 

   OnPictureSavedListener picSaveListener = new OnPictureSavedListener() {

    @Override
    public void onPictureSaved(Uri uri) {

    }
};
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
  • Hi, I want to get bitmap of parent view and parent view contain mGPUImageView. But when I get bitmap from parent view it show only black screen. How can I do this? Thanks in advance – Ganesh Katikar Mar 28 '15 at 11:42