Created
February 24, 2022 16:34
-
-
Save developer-shubham101/dcb25d85129c2b83c581d1c0b80043f5 to your computer and use it in GitHub Desktop.
Android: Create thumbnail of video
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1) | |
public static Bitmap blurRenderScript(Context context, Bitmap srcBitmap, int radius) { | |
Bitmap bitmap = Bitmap.createBitmap( | |
srcBitmap.getWidth(), srcBitmap.getHeight(), | |
Bitmap.Config.ARGB_8888); | |
RenderScript renderScript = RenderScript.create(context); | |
Allocation blurInput = Allocation.createFromBitmap(renderScript, srcBitmap); | |
Allocation blurOutput = Allocation.createFromBitmap(renderScript, bitmap); | |
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(renderScript, | |
Element.U8_4(renderScript)); | |
blur.setInput(blurInput); | |
blur.setRadius(radius); // radius must be 0 < r <= 25 | |
blur.forEach(blurOutput); | |
blurOutput.copyTo(bitmap); | |
renderScript.destroy(); | |
return bitmap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment