Exemple #1
0
  /**
   * 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;
  }
Exemple #2
0
  /**
   * Gets the images for multiple filters on a image. This can be used to quickly get thumbnail
   * images for filters. <br>
   * Whenever a new Bitmap is ready, the listener will be called with the bitmap. The order of the
   * calls to the listener will be the same as the filter order.
   *
   * @param bitmap the bitmap on which the filters will be applied
   * @param filters the filters which will be applied on the bitmap
   * @param listener the listener on which the results will be notified
   */
  public static void getBitmapForMultipleFilters(
      final Bitmap bitmap,
      final List<GPUImageFilter> filters,
      final ResponseListener<Bitmap> listener) {
    if (filters.isEmpty()) {
      return;
    }
    GPUImageRenderer renderer = new GPUImageRenderer(filters.get(0));
    renderer.setImageBitmap(bitmap, false);
    PixelBuffer buffer = new PixelBuffer(bitmap.getWidth(), bitmap.getHeight());
    buffer.setRenderer(renderer);

    for (GPUImageFilter filter : filters) {
      renderer.setFilter(filter);
      listener.response(buffer.getBitmap());
      filter.destroy();
    }
    renderer.deleteImage();
    buffer.destroy();
  }
Exemple #3
0
 /**
  * Sets the image on which the filter should be applied.
  *
  * @param bitmap the new image
  */
 public void setImage(final Bitmap bitmap) {
   mCurrentBitmap = bitmap;
   mRenderer.setImageBitmap(bitmap, false);
   requestRender();
 }