Stay organized with collections
Save and categorize content based on your preferences.
Provides classes that allow you to apply a variety of visual effects to images and
videos. For example, you can easily fix red-eye, convert an image to grayscale,
adjust brightness, adjust saturation, rotate an image, apply a fisheye effect, and much more. The
system performs all effects processing on the GPU to obtain maximum performance.
For maximum performance, effects are applied directly to OpenGL textures, so your application
must have a valid OpenGL context before it can use the effects APIs. The textures to which you apply
effects may be from bitmaps, videos or even the camera. However, there are certain restrictions that
textures must meet:
- They must be bound to a
GL_TEXTURE_2D
texture image
- They must contain at least one mipmap level
An Effect
object defines a single media effect that you can apply to
an image frame. The basic workflow to create an Effect
is:
- Call
EffectContext.createWithCurrentGlContext()
from your OpenGL ES 2.0 context.
- Use the returned
EffectContext
to call EffectContext.getFactory()
, which returns an instance
of EffectFactory
.
- Call
createEffect()
, passing it an
effect name from EffectFactory
, such as EFFECT_FISHEYE
or EFFECT_VIGNETTE
.
You can adjust an effect\u2019s parameters by calling setParameter()
and passing a parameter name and parameter value. Each type of effect accepts
different parameters, which are documented with the effect name. For example, EFFECT_FISHEYE
has one parameter for the scale
of the
distortion.
To apply an effect on a texture, call apply()
on the
Effect
and pass in the input texture, its width and height, and the output
texture. The input texture must be bound to a GL_TEXTURE_2D
texture
image (usually done by calling the glTexImage2D()
function). You may provide multiple mipmap levels. If the output texture has not been bound to a
texture image, it will be automatically bound by the effect as a GL_TEXTURE_2D
and with one mipmap level (0), which will have the same
size as the input.
Note: All effects listed in EffectFactory
are guaranteed to be supported. However, some additional effects
available from external libraries are not supported by all devices, so you must first check if the
desired effect from the external library is supported by calling isEffectSupported()
.
Interfaces
EffectUpdateListener |
Some effects may issue callbacks to inform the host of changes to the effect state.
|
Classes
Effect |
Effects are high-performance transformations that can be applied to image frames.
|
EffectContext |
An EffectContext keeps all necessary state information to run Effects within a Open GL ES 2.0
context.
|
EffectFactory |
The EffectFactory class defines the list of available Effects, and provides functionality to
inspect and instantiate them.
|
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# android.media.effect\n\nAdded in [API level 14](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\nandroid.media.effect\n====================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/media/effect/package-summary \"View this page in Kotlin\") \\|Java\n\nProvides classes that allow you to apply a variety of visual effects to images and\nvideos. For example, you can easily fix red-eye, convert an image to grayscale,\nadjust brightness, adjust saturation, rotate an image, apply a fisheye effect, and much more. The\nsystem performs all effects processing on the GPU to obtain maximum performance.\n\nFor maximum performance, effects are applied directly to OpenGL textures, so your application\nmust have a valid OpenGL context before it can use the effects APIs. The textures to which you apply\neffects may be from bitmaps, videos or even the camera. However, there are certain restrictions that\ntextures must meet:\n\n1. They must be bound to a [GL_TEXTURE_2D](/reference/android/opengl/GLES20#GL_TEXTURE_2D) texture image\n2. They must contain at least one mipmap level\n\nAn [Effect](/reference/android/media/effect/Effect) object defines a single media effect that you can apply to\nan image frame. The basic workflow to create an [Effect](/reference/android/media/effect/Effect) is:\n\n1. Call [EffectContext.createWithCurrentGlContext()](/reference/android/media/effect/EffectContext#createWithCurrentGlContext()) from your OpenGL ES 2.0 context.\n2. Use the returned [EffectContext](/reference/android/media/effect/EffectContext) to call [EffectContext.getFactory()](/reference/android/media/effect/EffectContext#getFactory()), which returns an instance of [EffectFactory](/reference/android/media/effect/EffectFactory).\n3. Call [createEffect()](/reference/android/media/effect/EffectFactory#createEffect(java.lang.String)), passing it an effect name from [EffectFactory](/reference/android/media/effect/EffectFactory), such as [EFFECT_FISHEYE](/reference/android/media/effect/EffectFactory#EFFECT_FISHEYE) or [EFFECT_VIGNETTE](/reference/android/media/effect/EffectFactory#EFFECT_VIGNETTE).\n\nYou can adjust an effect\\\\u2019s parameters by calling [setParameter()](/reference/android/media/effect/Effect#setParameter(java.lang.String,%20java.lang.Object)) and passing a parameter name and parameter value. Each type of effect accepts\ndifferent parameters, which are documented with the effect name. For example, [EFFECT_FISHEYE](/reference/android/media/effect/EffectFactory#EFFECT_FISHEYE) has one parameter for the `scale` of the\ndistortion.\n\nTo apply an effect on a texture, call [apply()](/reference/android/media/effect/Effect#apply(int,%20int,%20int,%20int)) on the\n[Effect](/reference/android/media/effect/Effect) and pass in the input texture, its width and height, and the output\ntexture. The input texture must be bound to a [GL_TEXTURE_2D](/reference/android/opengl/GLES20#GL_TEXTURE_2D) texture\nimage (usually done by calling the [glTexImage2D()](/reference/android/opengl/GLES20#glTexImage2D(int,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20java.nio.Buffer))\nfunction). You may provide multiple mipmap levels. If the output texture has not been bound to a\ntexture image, it will be automatically bound by the effect as a [GL_TEXTURE_2D](/reference/android/opengl/GLES20#GL_TEXTURE_2D) and with one mipmap level (0), which will have the same\nsize as the input.\n\n**Note:** All effects listed in [EffectFactory](/reference/android/media/effect/EffectFactory) are guaranteed to be supported. However, some additional effects\navailable from external libraries are not supported by all devices, so you must first check if the\ndesired effect from the external library is supported by calling [isEffectSupported()](/reference/android/media/effect/EffectFactory#isEffectSupported(java.lang.String)).\n\nInterfaces\n----------\n\n|------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|\n| [EffectUpdateListener](/reference/android/media/effect/EffectUpdateListener) | Some effects may issue callbacks to inform the host of changes to the effect state. |\n\nClasses\n-------\n\n|----------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|\n| [Effect](/reference/android/media/effect/Effect) | Effects are high-performance transformations that can be applied to image frames. |\n| [EffectContext](/reference/android/media/effect/EffectContext) | An EffectContext keeps all necessary state information to run Effects within a Open GL ES 2.0 context. |\n| [EffectFactory](/reference/android/media/effect/EffectFactory) | The EffectFactory class defines the list of available Effects, and provides functionality to inspect and instantiate them. |\n\n-\n\n Interfaces\n ----------\n\n - [EffectUpdateListener](/reference/android/media/effect/EffectUpdateListener)\n-\n\n Classes\n -------\n\n - [Effect](/reference/android/media/effect/Effect)\n - [EffectContext](/reference/android/media/effect/EffectContext)\n - [EffectFactory](/reference/android/media/effect/EffectFactory)"]]