/** * Gets the given bitmap with current filter applied as a Bitmap. * * @param bitmap the bitmap on which the current filter should be applied * @return the bitmap with filter applied */ public Bitmap getBitmapWithFilterApplied(final Bitmap bitmap) { if (mGlSurfaceView != null) { mRenderer.deleteImage(); mRenderer.runOnDraw( new Runnable() { @Override public void run() { synchronized (mFilter) { mFilter.destroy(); mFilter.notify(); } } }); synchronized (mFilter) { requestRender(); try { mFilter.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } } GPUImageRenderer renderer = new GPUImageRenderer(mFilter); renderer.setRotation( Rotation.NORMAL, mRenderer.isFlippedHorizontally(), mRenderer.isFlippedVertically()); renderer.setScaleType(mScaleType); PixelBuffer buffer = new PixelBuffer(bitmap.getWidth(), bitmap.getHeight()); buffer.setRenderer(renderer); renderer.setImageBitmap(bitmap, false); Bitmap result = buffer.getBitmap(); mFilter.destroy(); renderer.deleteImage(); buffer.destroy(); mRenderer.setFilter(mFilter); if (mCurrentBitmap != null) { mRenderer.setImageBitmap(mCurrentBitmap, false); } requestRender(); return result; }
/** * Sets the rotation of the displayed image. * * @param rotation new rotation */ public void setRotation(Rotation rotation) { mRenderer.setRotation(rotation); }