GPUImage for Android

repository·master·Indexed 27 days ago

https://github.com/wasabeef/android-gpuimage

An image processing library inspired by the iOS GPUImage framework that uses OpenGL ES 2.0 to apply vertex and fragment shaders (filters) to images and videos. It provides GPUImage for headless or GLSurfaceView processing and GPUImageView for simplified XML integration.

Tokens
943
Snippets
4
Records
5
Agent score
44%

What's inside android-gpuimage

  1. Install GPUImage via Gradle

    master

    Add the following dependency to your build.gradle file to use GPUImage in your Android project. Ensure mavenCentral() is included in your repositories block.

    Note: Replace 2.x.x with the latest version available.

    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation 'jp.co.cyberagent.android:gpuimage:2.x.x'
    }
  2. Use GPUImageView for easy XML integration

    master

    GPUImageView is a specialized view that simplifies integration via XML.

    XML Configuration

    Use the app:gpuimage_surface_type attribute to choose between surface_view or texture_view.

    <jp.co.cyberagent.android.gpuimage.GPUImageView
        android:id="@+id/gpuimageview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:gpuimage_show_loading="false"
        app:gpuimage_surface_type="texture_view" />

    Programmatic Usage

    Interact with the view instance to set images, filters, and save results.

    Example (Java):

    Uri imageUri = ...;
    gpuImageView = findViewById(R.id.gpuimageview);
    gpuImageView.setImage(imageUri); // this loads image on the current thread, should be run in a thread
    gpuImageView.setFilter(new GPUImageSepiaFilter());
    
    // Later when image should be saved saved:
    gpuImageView.saveToPictures("GPUImage", "ImageWithFilter.jpg", null);
  3. Use GPUImage without a preview (Headless/Background processing)

    master

    If you only need to process images without displaying them on screen, you can use GPUImage directly without attaching a surface view.

    Note: As with the preview method, setImage(Uri) should be called from a background thread.

    Example (Kotlin):

    val imageUri: Uri = ...
    gpuImage = GPUImage(this)
    gpuImage.setFilter(GPUImageSepiaFilter())
    gpuImage.setImage(imageUri)
    gpuImage.saveToPictures("GPUImage", "ImageWithFilter.jpg", null)
  4. Use GPUImage with a GLSurfaceView preview

    master

    To use GPUImage with a manual GLSurfaceView for image preview and filtering:

    1. Initialize GPUImage with your context.
    2. Attach a GLSurfaceView using setGLSurfaceView().
    3. Load an image using setImage(Uri). Warning: This method loads the image on the current thread; you should run it in a background thread to avoid blocking the UI.
    4. Apply a filter using setFilter().
    5. Save the result using saveToPictures().

    Example (Kotlin):

    val imageUri: Uri = ...
    gpuImage = GPUImage(this)
    gpuImage.setGLSurfaceView(findViewById<GLSurfaceView>(R.id.surfaceView))
    gpuImage.setImage(imageUri) // this loads image on the current thread, should be run in a thread
    gpuImage.setFilter(GPUImageSepiaFilter())
    
    // Later when image should be saved saved:
    gpuImage.saveToPictures("GPUImage", "ImageWithFilter.jpg", null)