android.support.v8.renderscript.Element类的使用及代码示例

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

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

Element介绍

暂无

代码示例

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

/**
 * @param context Context to create the {@link RenderScript}
 */
public SupportRenderScriptBlur(Context context) {
  renderScript = RenderScript.create(context);
  blurScript = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
}

代码示例来源:origin: zoff99/ToxAndroidRefImpl

yuvToRgb = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));
Type.Builder yuvType = new Type.Builder(rs, Element.U8(rs)).setX(frame_width_px).setY(frame_height_px);
yuvType.setYuvFormat(ImageFormat.YV12);
alloc_in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT);
Type.Builder rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(frame_width_px).setY(frame_height_px);
alloc_out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT);

代码示例来源:origin: 500px/500px-android-blur

private void initializeRenderScript(Context context) {
  mRenderScript = RenderScript.create(context);
  mBlurScript = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));
}

代码示例来源:origin: aa112901/remusic

public static Drawable createBlurredImageFromBitmap(Bitmap bitmap, Context context, int inSampleSize) {
  RenderScript rs = RenderScript.create(context);
  final BitmapFactory.Options options = new BitmapFactory.Options();
  options.inSampleSize = inSampleSize;
  ByteArrayOutputStream stream = new ByteArrayOutputStream();
  bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  byte[] imageInByte = stream.toByteArray();
  ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);
  Bitmap blurTemplate = BitmapFactory.decodeStream(bis, null, options);
  final android.support.v8.renderscript.Allocation input = android.support.v8.renderscript.Allocation.createFromBitmap(rs, blurTemplate);
  final android.support.v8.renderscript.Allocation output = android.support.v8.renderscript.Allocation.createTyped(rs, input.getType());
  final android.support.v8.renderscript.ScriptIntrinsicBlur script = android.support.v8.renderscript.ScriptIntrinsicBlur.create(rs, android.support.v8.renderscript.Element.U8_4(rs));
  script.setRadius(8f);
  script.setInput(input);
  script.forEach(output);
  output.copyTo(blurTemplate);
  return new BitmapDrawable(context.getResources(), blurTemplate);
}

代码示例来源:origin: naman14/Timber

public static Drawable createBlurredImageFromBitmap(Bitmap bitmap, Context context, int inSampleSize) {

    RenderScript rs = RenderScript.create(context);
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = inSampleSize;

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] imageInByte = stream.toByteArray();
    ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);
    Bitmap blurTemplate = BitmapFactory.decodeStream(bis, null, options);

    final android.support.v8.renderscript.Allocation input = android.support.v8.renderscript.Allocation.createFromBitmap(rs, blurTemplate);
    final android.support.v8.renderscript.Allocation output = android.support.v8.renderscript.Allocation.createTyped(rs, input.getType());
    final android.support.v8.renderscript.ScriptIntrinsicBlur script = android.support.v8.renderscript.ScriptIntrinsicBlur.create(rs, android.support.v8.renderscript.Element.U8_4(rs));
    script.setRadius(8f);
    script.setInput(input);
    script.forEach(output);
    output.copyTo(blurTemplate);

    return new BitmapDrawable(context.getResources(), blurTemplate);
  }
}

代码示例来源:origin: north2016/T-MVP

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

代码示例来源:origin: huazhiyuan2008/RecyclerViewCardGallery

ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

代码示例来源:origin: mmin18/RealtimeBlurView

try {
  mRenderScript = RenderScript.create(getContext());
  mBlurScript = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));
} catch (android.support.v8.renderscript.RSRuntimeException e) {
  if (isDebug(getContext())) {

代码示例来源:origin: felipecsl/GifImageView

public Bitmap blur(Bitmap image) {
 if (image == null)
  return null;
 image = RGB565toARGB888(image);
 if (!configured) {
  input = Allocation.createFromBitmap(rs, image);
  output = Allocation.createTyped(rs, input.getType());
  script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  script.setRadius(BLUR_RADIUS);
  configured = true;
 } else
  input.copyFrom(image);
 script.setInput(input);
 script.forEach(output);
 output.copyTo(image);
 return image;
}

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

public BestBlur(Context context) {
 mRS = RenderScript.create(context);
 mSIBlur = ScriptIntrinsicBlur.create(mRS, Element.U8_4(mRS));
 mSIGrey = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS));
}

代码示例来源:origin: brainysoon/cyberCar

public static Drawable createBlurredImageFromBitmap(Bitmap bitmap, Context context, int inSampleSize) {
  RenderScript rs = RenderScript.create(context);
  final BitmapFactory.Options options = new BitmapFactory.Options();
  options.inSampleSize = inSampleSize;
  ByteArrayOutputStream stream = new ByteArrayOutputStream();
  bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  byte[] imageInByte = stream.toByteArray();
  ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);
  Bitmap blurTemplate = BitmapFactory.decodeStream(bis, null, options);
  final android.support.v8.renderscript.Allocation input = android.support.v8.renderscript.Allocation.createFromBitmap(rs, blurTemplate);
  final android.support.v8.renderscript.Allocation output = android.support.v8.renderscript.Allocation.createTyped(rs, input.getType());
  final android.support.v8.renderscript.ScriptIntrinsicBlur script = android.support.v8.renderscript.ScriptIntrinsicBlur.create(rs, android.support.v8.renderscript.Element.U8_4(rs));
  script.setRadius(8f);
  script.setInput(input);
  script.forEach(output);
  output.copyTo(blurTemplate);
  return new BitmapDrawable(context.getResources(), blurTemplate);
}

代码示例来源:origin: rohanoid5/Muzesto

public static Drawable createBlurredImageFromBitmap(Bitmap bitmap, Context context, int inSampleSize) {
  RenderScript rs = RenderScript.create(context);
  final BitmapFactory.Options options = new BitmapFactory.Options();
  options.inSampleSize = inSampleSize;
  ByteArrayOutputStream stream = new ByteArrayOutputStream();
  bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  byte[] imageInByte = stream.toByteArray();
  ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);
  Bitmap blurTemplate = BitmapFactory.decodeStream(bis, null, options);
  final android.support.v8.renderscript.Allocation input = android.support.v8.renderscript.Allocation.createFromBitmap(rs, blurTemplate);
  final android.support.v8.renderscript.Allocation output = android.support.v8.renderscript.Allocation.createTyped(rs, input.getType());
  final android.support.v8.renderscript.ScriptIntrinsicBlur script = android.support.v8.renderscript.ScriptIntrinsicBlur.create(rs, android.support.v8.renderscript.Element.U8_4(rs));
  script.setRadius(8f);
  script.setInput(input);
  script.forEach(output);
  output.copyTo(blurTemplate);
  return new BitmapDrawable(context.getResources(), blurTemplate);
}

代码示例来源:origin: pinguo-zhouwei/EasyBlur

/**
 *  使用RenderScript 模糊图片
 * @param context
 * @param source
 * @return
 */
private static Bitmap rsBlur(Context context,Bitmap source,int radius,float scale){
  Log.i(TAG,"origin size:"+source.getWidth()+"*"+source.getHeight());
  int width = Math.round(source.getWidth() * scale);
  int height = Math.round(source.getHeight() * scale);
  Bitmap inputBmp = Bitmap.createScaledBitmap(source,width,height,false);
  RenderScript renderScript =  RenderScript.create(context);
  Log.i(TAG,"scale size:"+inputBmp.getWidth()+"*"+inputBmp.getHeight());
  // Allocate memory for Renderscript to work with
  final Allocation input = Allocation.createFromBitmap(renderScript,inputBmp);
  final Allocation output = Allocation.createTyped(renderScript,input.getType());
  // Load up an instance of the specific script that we want to use.
  ScriptIntrinsicBlur scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
  scriptIntrinsicBlur.setInput(input);
  // Set the blur radius
  scriptIntrinsicBlur.setRadius(radius);
  // Start the ScriptIntrinisicBlur
  scriptIntrinsicBlur.forEach(output);
  // Copy the output to the blurred bitmap
  output.copyTo(inputBmp);
  renderScript.destroy();
return inputBmp;
}

代码示例来源:origin: iQueSoft/iQuePhoto

private Bitmap getBlurBitmap(Context context, Bitmap bitmap, int width, int height) {
  Bitmap src = bitmap.copy(bitmap.getConfig(), true);
  Bitmap scaledBitmap = Bitmap.createScaledBitmap(src, width, height, false);
  Bitmap outputBitmap = Bitmap.createBitmap(scaledBitmap);
  RenderScript rs = RenderScript.create(context);
  ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  Allocation tmpIn = Allocation.createFromBitmap(rs, scaledBitmap);
  Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
  theIntrinsic.setRadius(10f);
  theIntrinsic.setInput(tmpIn);
  theIntrinsic.forEach(tmpOut);
  tmpOut.copyTo(outputBitmap);
  return outputBitmap;
}

代码示例来源:origin: tomahawk-player/tomahawk-android

@Override
public Bitmap transform(Bitmap source) {
  try {
    int scaledWidth = source.getWidth() / mSampling;
    int scaledHeight = source.getHeight() / mSampling;
    Bitmap bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(source, 0, 0, paint);
    RenderScript rs = RenderScript.create(mContext);
    Allocation input = Allocation.createFromBitmap(rs, bitmap,
        Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
    Allocation output = Allocation.createTyped(rs, input.getType());
    ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    blur.setInput(input);
    blur.setRadius(mRadius);
    blur.forEach(output);
    output.copyTo(bitmap);
    source.recycle();
    rs.destroy();
    return bitmap;
  } catch (RSRuntimeException e) {
    Log.e(TAG, "transform - ", e);
    return source;
  }
}

代码示例来源:origin: Rance935/SectorMenu

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@WorkerThread
private Bitmap getBlurBitmap(Context context, Bitmap inBitmap, float radius) {
  if (context == null || inBitmap == null) {
    throw new IllegalArgumentException("have not called setParams() before call execute()");
  }
  int width = Math.round(inBitmap.getWidth() * SCALE);
  int height = Math.round(inBitmap.getHeight() * SCALE);
  Bitmap in = Bitmap.createScaledBitmap(inBitmap, width, height, false);
  Bitmap out = Bitmap.createBitmap(in);
  RenderScript rs = RenderScript.create(context);
  ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  Allocation allocationIn = Allocation.createFromBitmap(rs, in);
  Allocation allocationOut = Allocation.createFromBitmap(rs, out);
  blurScript.setRadius(radius);
  blurScript.setInput(allocationIn);
  blurScript.forEach(allocationOut);
  allocationOut.copyTo(out);
  allocationIn.destroy();
  allocationOut.destroy();
  blurScript.destroy();
  rs.destroy();
  return out;
}

代码示例来源:origin: f2prateek/device-frame-generator

ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
blurScript.setRadius(backgroundBlurRadius);

代码示例来源:origin: sregg/spotify-tv

@Override
public Bitmap transform(Bitmap bitmap) {
  // Create another bitmap that will hold the results of the filter.
  Bitmap blurredBitmap = Bitmap.createBitmap(bitmap);
  // Allocate memory for Renderscript to work with
  Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_FULL, Allocation.USAGE_SHARED);
  Allocation output = Allocation.createTyped(rs, input.getType());
  // Load up an instance of the specific script that we want to use.
  ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  script.setInput(input);
  // Set the blur radius
  script.setRadius(10);
  // Start the ScriptIntrinisicBlur
  script.forEach(output);
  // Copy the output to the blurred bitmap
  output.copyTo(blurredBitmap);
  // recycle original
  bitmap.recycle();
  return blurredBitmap;
}

代码示例来源:origin: googlecodelabs/android-workmanager

Allocation outAlloc = Allocation.createTyped(rsContext, inAlloc.getType());
ScriptIntrinsicBlur theIntrinsic =
    ScriptIntrinsicBlur.create(rsContext, Element.U8_4(rsContext));
theIntrinsic.setRadius(10.f);
theIntrinsic.setInput(inAlloc);

代码示例来源:origin: vipulasri/Artisto_capstone

@Override
  public void process(Bitmap bitmap)
  {
    Allocation alloc = Allocation.createFromBitmap(mRenderScript, bitmap);
    ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));
    blur.setInput(alloc);
    blur.setRadius(BLUR_RADIUS_IMAGE);
    blur.forEach(alloc);
    alloc.copyTo(bitmap);
  }
}

相关文章

微信公众号

最新文章

更多

Element类方法