Android: Create thumbnail of video
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
@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; } |