本文整理了Java中android.renderscript.Allocation.createTyped()
方法的一些代码示例,展示了Allocation.createTyped()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Allocation.createTyped()
方法的具体详情如下:
包路径:android.renderscript.Allocation
类名称:Allocation
方法名:createTyped
暂无
代码示例来源:origin: cymcsg/UltimateAndroid
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));
代码示例来源:origin: Dimezis/BlurView
/**
* @param bitmap bitmap to blur
* @param blurRadius blur radius (1..25)
* @return blurred bitmap
*/
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
@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: CameraKit/blurkit-android
public Bitmap blur(Bitmap src, int radius) {
final Allocation input = Allocation.createFromBitmap(rs, src);
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(src);
return src;
}
代码示例来源:origin: wasabeef/glide-transformations
input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
output = Allocation.createTyped(rs, input.getType());
blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
代码示例来源:origin: wasabeef/Blurry
input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
output = Allocation.createTyped(rs, input.getType());
blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
代码示例来源:origin: multidots/android-app-common-tasks
sentBitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs,
input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs,
代码示例来源:origin: multidots/android-app-common-tasks
sentBitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs,
input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs,
代码示例来源:origin: Blizzard-liu/AndroidUtils
sentBitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs,
input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs,
代码示例来源:origin: jingle1267/android-utils
sentBitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs,
input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs,
代码示例来源:origin: sunfusheng/GlideImageView
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap rsBlur(Context context, Bitmap toTransform, int radius) {
RenderScript renderScript = RenderScript.create(context);
Allocation input = Allocation.createFromBitmap(renderScript, toTransform);
Allocation output = Allocation.createTyped(renderScript, input.getType());
ScriptIntrinsicBlur scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
scriptIntrinsicBlur.setInput(input);
scriptIntrinsicBlur.setRadius(radius);
scriptIntrinsicBlur.forEach(output);
output.copyTo(toTransform);
renderScript.destroy();
return toTransform;
}
代码示例来源:origin: guolindev/giffun
input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
output = Allocation.createTyped(rs, input.getType());
blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
代码示例来源:origin: SmartDengg/RxBlur
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @Override
public Bitmap transform(@NonNull Bitmap source) {
Bitmap blurredBitmap =
Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(blurredBitmap);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
paint.setAntiAlias(true);
canvas.drawBitmap(source, 0, 0, paint);
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 scriptIntrinsicBlur =
ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
scriptIntrinsicBlur.setInput(input);
scriptIntrinsicBlur.setRadius(blurRadius);
scriptIntrinsicBlur.forEach(output);
output.copyTo(blurredBitmap);
source.recycle();
scriptIntrinsicBlur.destroy();
return blurredBitmap;
}
代码示例来源:origin: chuanqi305/rscnn
@Override
public void computeOutputShape() {
outputShape = inputShape[0];
if(softmaxScript!=null){
int n = inputShape[0][0];
int h = inputShape[0][1];
int w = inputShape[0][2];
int c = inputShape[0][3];
Type expSumType = Type.createX(renderScript, Element.F32(renderScript), n * h * w);
expSumAlloc = Allocation.createTyped(renderScript, expSumType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT);
softmaxScript.set_channel(c);
softmaxScript.set_expSum(expSumAlloc);
}
}
}
代码示例来源:origin: chuanqi305/rscnn
@Override
public void setup(){
int n = inputShape[0][0];
int h = inputShape[0][1];
int w = inputShape[0][2];
int c = inputShape[0][3];
Type expSumType = Type.createX(renderScript, Element.F32(renderScript), n * h * w);
expSumAlloc = Allocation.createTyped(renderScript, expSumType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT);
softmaxScript = new ScriptC_Softmax(renderScript);
softmaxScript.set_channel(c);
softmaxScript.set_expSum(expSumAlloc);
}
代码示例来源:origin: xuhongv/SmartHome
@Override
public Bitmap transform(Bitmap bitmap) {
// Create another bitmap that will hold the results of the filter.
Bitmap blurredBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
// Allocate memory for Renderscript to work with
Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, 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(25);
// Start the ScriptIntrinisicBlur
script.forEach(output);
// Copy the output to the blurred bitmap
output.copyTo(blurredBitmap);
bitmap.recycle();
return blurredBitmap;
}
代码示例来源:origin: dabutaizha/juzimi
private static Bitmap blurRenderScript(Context context, Bitmap smallBitmap, int radius) {
RenderScript rs = RenderScript.create(context);
Bitmap blurredBitmap = smallBitmap.copy(Bitmap.Config.ARGB_8888, true);
Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, 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);
script.setRadius(radius);
script.forEach(output);
output.copyTo(blurredBitmap);
return blurredBitmap;
}
代码示例来源:origin: HelloChenJinJun/TestChat
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
RenderScript rs = null;
try {
rs = RenderScript.create(context);
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(radius);
blur.forEach(output);
output.copyTo(bitmap);
} finally {
if (rs != null) {
rs.destroy();
}
}
return bitmap;
}
}
代码示例来源:origin: whyalwaysmea/BigBoom
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
RenderScript rs = null;
try {
rs = RenderScript.create(context);
rs.setMessageHandler(new RenderScript.RSMessageHandler());
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(radius);
blur.forEach(output);
output.copyTo(bitmap);
} finally {
if (rs != null) {
rs.destroy();
}
}
return bitmap;
}
}
代码示例来源:origin: chuanqi305/rscnn
protected void allocFeatureMapNoPad()
{
Type.Builder outputType = new Type.Builder(renderScript, Element.F32(renderScript));
outputType.setZ(outputShape[0]);
outputType.setY(outputShape[1] * outputShape[2]);
outputType.setX(outputShape[3]);
Allocation outAllocation = Allocation.createTyped(renderScript, outputType.create());
FeatureMap output = new FeatureMap();
output.setFeatureMap(outAllocation);
output.setN(outputShape[0]);
output.setH(outputShape[1]);
output.setW(outputShape[2]);
output.setC(outputShape[3]);
output.setPad4(false);
if(this.featureMapOutput!=null){
((FeatureMap)featureMapOutput).getFeatureMap().destroy();
}
this.featureMapOutput = output;
}
代码示例来源:origin: chuanqi305/rscnn
protected void allocFeatureMap()
{
Type.Builder outputType = new Type.Builder(renderScript, Element.F32(renderScript));
outputType.setZ(outputShape[0]);
outputType.setY(outputShape[1] * outputShape[2]);
outputType.setX(getOutputChannelAligned());
Allocation outAllocation = Allocation.createTyped(renderScript, outputType.create());
FeatureMap output = new FeatureMap();
output.setFeatureMap(outAllocation);
output.setN(outputShape[0]);
output.setH(outputShape[1]);
output.setW(outputShape[2]);
output.setC(outputShape[3]);
output.setPad4(true);
if(this.featureMapOutput!=null){
((FeatureMap)featureMapOutput).getFeatureMap().destroy();
}
this.featureMapOutput = output;
}
内容来源于网络,如有侵权,请联系作者删除!