android.renderscript.Element.U8_4()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(290)

本文整理了Java中android.renderscript.Element.U8_4()方法的一些代码示例,展示了Element.U8_4()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.U8_4()方法的具体详情如下:
包路径:android.renderscript.Element
类名称:Element
方法名:U8_4

Element.U8_4介绍

暂无

代码示例

代码示例来源:origin: Dimezis/BlurView

  1. /**
  2. * @param context Context to create the {@link RenderScript}
  3. */
  4. @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
  5. public RenderScriptBlur(Context context) {
  6. renderScript = RenderScript.create(context);
  7. blurScript = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
  8. }

代码示例来源:origin: HotBitmapGG/bilibili-android-client

  1. /**
  2. * 图片高斯模糊具体实现方法
  3. */
  4. public static Bitmap blur(Context context, Bitmap image, float radius) {
  5. // 计算图片缩小后的长宽
  6. int width = Math.round(image.getWidth() * BITMAP_SCALE);
  7. int height = Math.round(image.getHeight() * BITMAP_SCALE);
  8. // 将缩小后的图片做为预渲染的图片。
  9. Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
  10. // 创建一张渲染后的输出图片。
  11. Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
  12. // 创建RenderScript内核对象
  13. RenderScript rs = RenderScript.create(context);
  14. // 创建一个模糊效果的RenderScript的工具对象
  15. ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  16. // 由于RenderScript并没有使用VM来分配内存,所以需要使用Allocation类来创建和分配内存空间。
  17. // 创建Allocation对象的时候其实内存是空的,需要使用copyTo()将数据填充进去。
  18. Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
  19. Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
  20. // 设置渲染的模糊程度, 25f是最大模糊度
  21. blurScript.setRadius(radius);
  22. // 设置blurScript对象的输入内存
  23. blurScript.setInput(tmpIn);
  24. // 将输出数据保存到输出内存中
  25. blurScript.forEach(tmpOut);
  26. // 将数据填充到Allocation中
  27. tmpOut.copyTo(outputBitmap);
  28. return outputBitmap;
  29. }
  30. }

代码示例来源:origin: cymcsg/UltimateAndroid

  1. Allocation.USAGE_SCRIPT);
  2. final Allocation output = Allocation.createTyped(rs, input.getType());
  3. final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

代码示例来源:origin: CameraKit/blurkit-android

  1. public Bitmap blur(Bitmap src, int radius) {
  2. final Allocation input = Allocation.createFromBitmap(rs, src);
  3. final Allocation output = Allocation.createTyped(rs, input.getType());
  4. final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  5. script.setRadius(radius);
  6. script.setInput(input);
  7. script.forEach(output);
  8. output.copyTo(src);
  9. return src;
  10. }

代码示例来源:origin: wasabeef/glide-transformations

  1. Allocation.USAGE_SCRIPT);
  2. output = Allocation.createTyped(rs, input.getType());
  3. blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

代码示例来源:origin: wasabeef/Blurry

  1. Allocation.USAGE_SCRIPT);
  2. output = Allocation.createTyped(rs, input.getType());
  3. blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

代码示例来源:origin: multidots/android-app-common-tasks

  1. input.getType());
  2. final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs,
  3. Element.U8_4(rs));

代码示例来源:origin: multidots/android-app-common-tasks

  1. input.getType());
  2. final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs,
  3. Element.U8_4(rs));

代码示例来源:origin: Blizzard-liu/AndroidUtils

  1. input.getType());
  2. final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs,
  3. Element.U8_4(rs));

代码示例来源:origin: jingle1267/android-utils

  1. input.getType());
  2. final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs,
  3. Element.U8_4(rs));

代码示例来源:origin: sunfusheng/GlideImageView

  1. @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
  2. public static Bitmap rsBlur(Context context, Bitmap toTransform, int radius) {
  3. RenderScript renderScript = RenderScript.create(context);
  4. Allocation input = Allocation.createFromBitmap(renderScript, toTransform);
  5. Allocation output = Allocation.createTyped(renderScript, input.getType());
  6. ScriptIntrinsicBlur scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
  7. scriptIntrinsicBlur.setInput(input);
  8. scriptIntrinsicBlur.setRadius(radius);
  9. scriptIntrinsicBlur.forEach(output);
  10. output.copyTo(toTransform);
  11. renderScript.destroy();
  12. return toTransform;
  13. }

代码示例来源:origin: guolindev/giffun

  1. Allocation.USAGE_SCRIPT);
  2. output = Allocation.createTyped(rs, input.getType());
  3. blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

代码示例来源:origin: BrianValente/WAMOD

  1. /**
  2. * @param context Context to create the {@link RenderScript}
  3. */
  4. @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
  5. public RenderScriptBlur(Context context) {
  6. renderScript = RenderScript.create(context);
  7. blurScript = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
  8. }

代码示例来源:origin: ApplikeySolutions/OrionPreview

  1. public Bitmap blur(Context context, Bitmap image) {
  2. int width = Math.round(image.getWidth() * BITMAP_SCALE);
  3. int height = Math.round(image.getHeight() * BITMAP_SCALE);
  4. Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
  5. Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
  6. RenderScript rs = RenderScript.create(context);
  7. ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  8. Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
  9. Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
  10. theIntrinsic.setRadius(BLUR_RADIUS);
  11. theIntrinsic.setInput(tmpIn);
  12. theIntrinsic.forEach(tmpOut);
  13. tmpOut.copyTo(outputBitmap);
  14. return outputBitmap;
  15. }

代码示例来源:origin: nvllsvm/Audinaut

  1. public static Bitmap blur(Context context, Bitmap image) {
  2. int width = Math.round(image.getWidth() * BITMAP_SCALE);
  3. int height = Math.round(image.getHeight() * BITMAP_SCALE);
  4. Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
  5. Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
  6. RenderScript rs = RenderScript.create(context);
  7. ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  8. Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
  9. Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
  10. theIntrinsic.setRadius(BLUR_RADIUS);
  11. theIntrinsic.setInput(tmpIn);
  12. theIntrinsic.forEach(tmpOut);
  13. tmpOut.copyTo(outputBitmap);
  14. return outputBitmap;
  15. }
  16. }

代码示例来源:origin: SmartDengg/RxBlur

  1. @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @Override
  2. public Bitmap transform(@NonNull Bitmap source) {
  3. Bitmap blurredBitmap =
  4. Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
  5. Canvas canvas = new Canvas(blurredBitmap);
  6. Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
  7. paint.setAntiAlias(true);
  8. canvas.drawBitmap(source, 0, 0, paint);
  9. RenderScript renderScript = RenderScript.create(context);
  10. Allocation input =
  11. Allocation.createFromBitmap(renderScript, source, Allocation.MipmapControl.MIPMAP_FULL,
  12. Allocation.USAGE_SCRIPT);
  13. Allocation output = Allocation.createTyped(renderScript, input.getType());
  14. ScriptIntrinsicBlur scriptIntrinsicBlur =
  15. ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
  16. scriptIntrinsicBlur.setInput(input);
  17. scriptIntrinsicBlur.setRadius(blurRadius);
  18. scriptIntrinsicBlur.forEach(output);
  19. output.copyTo(blurredBitmap);
  20. source.recycle();
  21. scriptIntrinsicBlur.destroy();
  22. return blurredBitmap;
  23. }

代码示例来源:origin: zzkong/BaseProject

  1. /**
  2. * 图片模糊效果
  3. */
  4. public static Bitmap blurBitmap(Context context, Bitmap bitmap, float radius){
  5. Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
  6. RenderScript rs = RenderScript.create(context);
  7. ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  8. Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
  9. Allocation allOut = Allocation.createFromBitmap(rs, bitmap);
  10. blurScript.setRadius(radius);
  11. blurScript.setInput(allIn);
  12. blurScript.forEach(allOut);
  13. allOut.copyTo(outBitmap);
  14. bitmap.recycle();
  15. rs.destroy();
  16. return outBitmap;
  17. }

代码示例来源:origin: devendroid/SketchImage

  1. private Bitmap toBlur(Bitmap input, float i) {
  2. try {
  3. RenderScript rsScript = RenderScript.create(context);
  4. Allocation alloc = Allocation.createFromBitmap(rsScript, input);
  5. ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rsScript, Element.U8_4(rsScript));
  6. blur.setRadius((i * 25) / 100);
  7. blur.setInput(alloc);
  8. Bitmap result = Bitmap.createBitmap(input.getWidth(), input.getHeight(), Bitmap.Config.ARGB_8888);
  9. Allocation outAlloc = Allocation.createFromBitmap(rsScript, result);
  10. blur.forEach(outAlloc);
  11. outAlloc.copyTo(result);
  12. rsScript.destroy();
  13. return result;
  14. } catch (Exception e) {
  15. // TODO: handle exception
  16. return input;
  17. }
  18. }

代码示例来源:origin: xuhongv/SmartHome

  1. @Override
  2. public Bitmap transform(Bitmap bitmap) {
  3. // Create another bitmap that will hold the results of the filter.
  4. Bitmap blurredBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
  5. // Allocate memory for Renderscript to work with
  6. Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, Allocation.MipmapControl.MIPMAP_FULL, Allocation.USAGE_SHARED);
  7. Allocation output = Allocation.createTyped(rs, input.getType());
  8. // Load up an instance of the specific script that we want to use.
  9. ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  10. script.setInput(input);
  11. // Set the blur radius
  12. script.setRadius(25);
  13. // Start the ScriptIntrinisicBlur
  14. script.forEach(output);
  15. // Copy the output to the blurred bitmap
  16. output.copyTo(blurredBitmap);
  17. bitmap.recycle();
  18. return blurredBitmap;
  19. }

代码示例来源:origin: dabutaizha/juzimi

  1. private static Bitmap blurRenderScript(Context context, Bitmap smallBitmap, int radius) {
  2. RenderScript rs = RenderScript.create(context);
  3. Bitmap blurredBitmap = smallBitmap.copy(Bitmap.Config.ARGB_8888, true);
  4. Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, Allocation.MipmapControl.MIPMAP_FULL, Allocation.USAGE_SHARED);
  5. Allocation output = Allocation.createTyped(rs, input.getType());
  6. // Load up an instance of the specific script that we want to use.
  7. ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  8. script.setInput(input);
  9. script.setRadius(radius);
  10. script.forEach(output);
  11. output.copyTo(blurredBitmap);
  12. return blurredBitmap;
  13. }

相关文章