android.support.v8.renderscript.Allocation.createFromBitmap()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(13.8k)|赞(0)|评价(0)|浏览(135)

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

Allocation.createFromBitmap介绍

暂无

代码示例

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

mBlurInput = Allocation.createFromBitmap(mRenderScript, mBitmapToBlur,
    Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
mBlurOutput = Allocation.createTyped(mRenderScript, mBlurInput.getType());

代码示例来源: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: huazhiyuan2008/RecyclerViewCardGallery

Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);

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

Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
    Allocation.USAGE_SCRIPT);
Allocation output = Allocation.createTyped(rs, input.getType());

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

/**
 * @param bitmap     bitmap to blur
 * @param blurRadius blur radius (1..25)
 * @return blurred bitmap
 */
@Override
public final Bitmap blur(Bitmap bitmap, float blurRadius) {
  //Allocation will use the same backing array of pixels as bitmap if created with USAGE_SHARED flag
  Allocation inAllocation = Allocation.createFromBitmap(renderScript, bitmap);
  if (!canReuseAllocation(bitmap)) {
    if (outAllocation != null) {
      outAllocation.destroy();
    }
    outAllocation = Allocation.createTyped(renderScript, inAllocation.getType());
    lastBitmapWidth = bitmap.getWidth();
    lastBitmapHeight = bitmap.getHeight();
  }
  blurScript.setRadius(blurRadius);
  blurScript.setInput(inAllocation);
  //do not use inAllocation in forEach. it will cause visual artifacts on blurred Bitmap
  blurScript.forEach(outAllocation);
  outAllocation.copyTo(bitmap);
  inAllocation.destroy();
  return bitmap;
}

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

mBlurInput = Allocation.createFromBitmap(mRenderScript, mBitmapToBlur,
    Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
mBlurOutput = Allocation.createTyped(mRenderScript, mBlurInput.getType());

代码示例来源: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: 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: 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: 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: 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: 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: SmartDengg/RxBlur

mTmp1 = Allocation.createFromBitmap(mRS, src);
mTmp2 = Allocation.createFromBitmap(mRS, dest);

代码示例来源: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);
  }
}

代码示例来源:origin: dongorigin/AndroidDemo

public static Bitmap apply(Context context, Bitmap sentBitmap, int radius) {
  final Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
  final RenderScript rs = RenderScript.create(context);
  final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
  final Allocation output = Allocation.createTyped(rs, input.getType());
  final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  script.setRadius(radius);
  script.setInput(input);
  script.forEach(output);
  output.copyTo(bitmap);
  sentBitmap.recycle();
  rs.destroy();
  input.destroy();
  output.destroy();
  script.destroy();
  return bitmap;
}

代码示例来源:origin: erikcaffrey/Android-Spotify-MVP

@Override public Bitmap transform(Bitmap source) {
 Bitmap blurredBitmap;
 blurredBitmap = Bitmap.createBitmap(source);
 RenderScript renderScript = RenderScript.create(context);
 Allocation input =
   Allocation.createFromBitmap(renderScript, source, Allocation.MipmapControl.MIPMAP_FULL,
     Allocation.USAGE_SCRIPT);
 Allocation output = Allocation.createTyped(renderScript, input.getType());
 ScriptIntrinsicBlur script =
   ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
 script.setInput(input);
 script.setRadius(blurRadius);
 script.forEach(output);
 output.copyTo(blurredBitmap);
 return blurredBitmap;
}

代码示例来源:origin: alphamu/FrostyBackgroundTestApp

public static void blurBitmapWithRenderscript(RenderScript rs, Bitmap bitmap2) {
  //this will blur the bitmapOriginal with a radius of 25 and save it in bitmapOriginal
  final Allocation input = Allocation.createFromBitmap(rs, bitmap2); //use this constructor for best performance, because it uses USAGE_SHARED mode which reuses memory
  final Allocation output = Allocation.createTyped(rs, input.getType());
  final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
  // must be >0 and <= 25
  script.setRadius(25f);
  script.setInput(input);
  script.forEach(output);
  output.copyTo(bitmap2);
}

相关文章