chrisbatt / AndroidFastImageProcessing

A framework for speeding up image processing on android devices by taking advantage of shaders on the GPU.
MIT License
285 stars 118 forks source link

Take filtered image as Bitmap #17

Open gkakasevski opened 10 years ago

gkakasevski commented 10 years ago

Hi all, I need the filtered image as Bitmap object at the end. How can I do that?

ghost commented 10 years ago

Hi gkakasevski, You can use code below:

BitmapOutput output;

public void getBitmap(){ GaussianBlurFilter gauu = new GaussianBlurFilter(2.0f); gauu.addTarget(screen); pipeline.pauseRendering(); input.addTarget(gauu); pipeline.startRendering(); output = new BitmapOutput(new BitmapOutputCallback() {

            @Override
            public void bitmapCreated(Bitmap bitmap) {
                // TODO Auto-generated method stub
                // Bitmap will return in this.
                                    saveFileShare(bitmap);
            }
        });
        gauu.addTarget(output);
        view.requestRender();

}

public void saveFileShare(Bitmap bm) { if (!PATH_SHARE.exists()) PATH_SHARE.mkdir(); Date dateNow = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); String datetime = dateFormat.format(dateNow); String imageName = datetime + ".png"; String fileImageShare = PATH_SHARE.getPath() + File.separator + imageName; FileOutputStream out = null; try { out = new FileOutputStream(fileImageShare); bm.compress(Bitmap.CompressFormat.JPEG, 80, out); } catch (Exception e) { e.printStackTrace(); } finally { try { out.close(); } catch (Throwable ignore) { } } }

Have a nice day!

gkakasevski commented 10 years ago

Tnx a lot :)