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

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

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

Allocation.getElement介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

Bitmap U8_4Bitmap;
   if(sentBitmap.getConfig() == Bitmap.Config.ARGB_8888) {
     U8_4Bitmap = sentBitmap;
   } else {
     U8_4Bitmap = sentBitmap.copy(Bitmap.Config.ARGB_8888, true);
   }
   //==============================
   Bitmap bitmap = Bitmap.createBitmap(U8_4Bitmap.getWidth(), U8_4Bitmap.getHeight(), U8_4Bitmap.getConfig());
   final RenderScript rs = RenderScript.create(context);
   final Allocation input = Allocation.createFromBitmap(rs,
       U8_4Bitmap,
       Allocation.MipmapControl.MIPMAP_NONE,
       Allocation.USAGE_SCRIPT);
   final Allocation output = Allocation.createTyped(rs, input.getType());
   final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, output.getElement());
   script.setRadius(radius);
   script.setInput(input);
   script.forEach(output);
   output.copyTo(bitmap);
   rs.destroy();
   return bitmap;

代码示例来源:origin: bxbxbai/ZhuanLan

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void blur(Bitmap bkg, View view) {
  long startMs = System.currentTimeMillis();
  float radius = 10;
  Bitmap overlay = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(overlay);
  canvas.translate(-view.getLeft(), -view.getTop());
  canvas.drawBitmap(bkg, 0, 0, null);
  RenderScript rs = RenderScript.create(this);
  Allocation allocation = Allocation.createFromBitmap(rs, overlay);
  ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, allocation.getElement());
  blur.setInput(allocation);
  blur.setRadius(radius);
  blur.forEach(allocation);
  allocation.copyTo(overlay);
  view.setBackground(new BitmapDrawable(getResources(), overlay));
  rs.destroy();
  StopWatch.log(System.currentTimeMillis() - startMs + "ms");
}

代码示例来源:origin: Vegen/SmartCampus

public static void blur(Bitmap bkg, View view, ImageView forecastBlur) {
  long start = System.currentTimeMillis();
  float radius = 18;
  float scaleFactor = 1.0f;
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor),
        (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    //canvas.translate(-view.getLeft(), -view.getTop());
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    canvas.drawBitmap(bkg, 0, 0, null);
    RenderScript rs = RenderScript.create(MyApplication.getInstance());
    Allocation overlayAlloc = Allocation.createFromBitmap(rs, overlay);
    ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement());
    blur.setInput(overlayAlloc);
    blur.setRadius(radius);
    blur.forEach(overlayAlloc);
    overlayAlloc.copyTo(overlay);
    forecastBlur.setImageDrawable(new BitmapDrawable(MyApplication.getInstance().getResources(), overlay));
    rs.destroy();
  }
  Log.e("cost", System.currentTimeMillis() - start + "");
}

代码示例来源:origin: chuanqi305/rscnn

@Override
public void computeFeatureMap() {
  int n = inputShape[0][0];
  int h = inputShape[0][1];
  int w = inputShape[0][2];
  int c = inputShape[0][3];
  int channelAligned = getInputChannelAligned();
  FeatureMap input = (FeatureMap) featureMapInput[0];
  Allocation inAllocation = input.getFeatureMap();
  if(inAllocation.getElement().getVectorSize()==4){
    softmaxScript.set_channelAligned(channelAligned);
  }
  else{
    softmaxScript.set_channelAligned(c);
  }
  softmaxScript.set_inBlob(inAllocation);
  Script.LaunchOptions option = new Script.LaunchOptions();
  option.setX(0, n * h * w * c);
  softmaxScript.forEach_compute_exp(option);
  option.setX(0, n * h * w);
  softmaxScript.forEach_compute_exp_sum(option);
  option.setX(0, n * h * w * c);
  softmaxScript.forEach_compute(option);
  featureMapOutput = featureMapInput[0];
}

相关文章