本文整理了Java中android.renderscript.Allocation
类的一些代码示例,展示了Allocation
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Allocation
类的具体详情如下:
包路径:android.renderscript.Allocation
类名称:Allocation
暂无
代码示例来源: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: Dimezis/BlurView
@Override
public final void destroy() {
blurScript.destroy();
renderScript.destroy();
if (outAllocation != null) {
outAllocation.destroy();
}
}
代码示例来源:origin: stackoverflow.com
//define this only once if blurring multiple times
RenderScript rs = RenderScript.create(context);
(...)
//this will blur the bitmapOriginal with a radius of 8 and save it in bitmapOriginal
final Allocation input = Allocation.createFromBitmap(rs, bitmapOriginal); //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));
script.setRadius(8f);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmapOriginal);
代码示例来源:origin: HotBitmapGG/bilibili-android-client
/**
* 图片高斯模糊具体实现方法
*/
public static Bitmap blur(Context context, Bitmap image, float radius) {
// 计算图片缩小后的长宽
int width = Math.round(image.getWidth() * BITMAP_SCALE);
int height = Math.round(image.getHeight() * BITMAP_SCALE);
// 将缩小后的图片做为预渲染的图片。
Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
// 创建一张渲染后的输出图片。
Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
// 创建RenderScript内核对象
RenderScript rs = RenderScript.create(context);
// 创建一个模糊效果的RenderScript的工具对象
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
// 由于RenderScript并没有使用VM来分配内存,所以需要使用Allocation类来创建和分配内存空间。
// 创建Allocation对象的时候其实内存是空的,需要使用copyTo()将数据填充进去。
Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
// 设置渲染的模糊程度, 25f是最大模糊度
blurScript.setRadius(radius);
// 设置blurScript对象的输入内存
blurScript.setInput(tmpIn);
// 将输出数据保存到输出内存中
blurScript.forEach(tmpOut);
// 将数据填充到Allocation中
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}
}
代码示例来源: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: eventtus/photo-editor-android
mBlurInput = Allocation.createFromBitmap(mRenderScript, mBitmapToBlur,
Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
mBlurOutput = Allocation.createTyped(mRenderScript, mBlurInput.getType());
代码示例来源: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: stackoverflow.com
mOutAllocation = Allocation.createTyped(mRS,mInAllocation.getType());
mScript = new ScriptC_Square(mRS, getResources(), R.raw.square);
mInAllocation.copyFrom(input);
mOutAllocation.copyTo(output); // copy the result that was stored in mOutAllocation into the array output
代码示例来源:origin: chuanqi305/rscnn
private static float[][] copyFromAllocation2D(Allocation allocation, int n, int c)
{
float[] alloc = new float[n * c];
float[][]output = new float[n][c];
allocation.copyTo(alloc);
int count = 0;
for(int i=0;i<n;i++){
for(int j=0;j<c;j++){
output[i][j] = alloc[count++];
}
}
return output;
}
代码示例来源: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: gearvrf/GearVRf-Demos
mInputAllocation = Allocation.createTyped(rs, yuvTypeBuilder.create(),
Allocation.USAGE_IO_INPUT | Allocation.USAGE_SCRIPT);
mInterAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create(),
Allocation.USAGE_SCRIPT);
mInputAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create(),
Allocation.USAGE_IO_INPUT | Allocation.USAGE_SCRIPT);
mOutputAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create(),
Allocation.USAGE_IO_OUTPUT | Allocation.USAGE_SCRIPT);
代码示例来源:origin: chuanqi305/rscnn
biasType = Type.createX(renderScript, Element.F32(renderScript), c);
kernelAllocation = Allocation.createTyped(renderScript, kernelType);
biasAllocation = Allocation.createTyped(renderScript, biasType);
kernelAllocation.copyFrom(weight);
biasAllocation.copyFrom(bias);
kernelAllocation.copyFromUnchecked(weightBuffer);
biasAllocation.copyFromUnchecked(biasBuffer);
代码示例来源:origin: eventtus/photo-editor-android
protected void blur(Bitmap bitmapToBlur, Bitmap blurredBitmap) {
mBlurInput.copyFrom(bitmapToBlur);
mBlurScript.setInput(mBlurInput);
mBlurScript.forEach(mBlurOutput);
mBlurOutput.copyTo(blurredBitmap);
}
代码示例来源:origin: chuanqi305/rscnn
public float[] getData1D(){
FeatureMap data = this;
int size = data.getFeatureMap().getBytesSize() / 4 ;
float[] output = new float[size];
data.getFeatureMap().copyTo(output);
return output;
}
代码示例来源:origin: chuanqi305/rscnn
if(old.getFeatureMap()!=null){
Allocation out = old.getFeatureMap();
if(out.getBytesSize()==outNum * outHeight * outWidth * outChannel * 4){
old.setN(outNum);
old.setH(outHeight);
out.destroy();
Allocation outAllocation = Allocation.createTyped(renderScript, outType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
FeatureMap output = new FeatureMap();
output.setFeatureMap(outAllocation);
代码示例来源:origin: chuanqi305/rscnn
@Override
public void setup()
{
int channel = outputShape[3];
int channelAlign = channel;
if(channel % 4 != 0){
channelAlign = channel + 4 - channel % 4;
}
scriptScale = new ScriptC_Scale(renderScript);
float[] scaleArray = new float[channelAlign];
float[] biasArray = new float[channelAlign];
for(int i=0;i<channel;i++){
scaleArray[i] = scale[i];
biasArray[i] = bias[i];
}
Allocation scaleAllocation;
Allocation biasAllocation;
Type scaleType = Type.createX(renderScript, Element.F32_4(renderScript), channelAlign / 4);
Type biasType = Type.createX(renderScript, Element.F32_4(renderScript), channelAlign / 4);
scaleAllocation = Allocation.createTyped(renderScript, scaleType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT);
scaleAllocation.copyFrom(scaleArray);
biasAllocation = Allocation.createTyped(renderScript, biasType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT);
biasAllocation.copyFrom(biasArray);
scriptScale.set_scale(scaleAllocation);
scriptScale.set_bias(biasAllocation);
}
代码示例来源:origin: stackoverflow.com
// Whatever.java
public void copyDoublesTo(double[] entries, Allocation target)
throws IOException {
if (!target.getType().getElement().isCompatible(Element.F64(mRS)))
throw new RSRuntimeException("Type mismatch: Element != F64");
if (target.getType().getCount() != entries.length)
throw new RSRuntimeException("Type mismatch: wrong # of entries");
mScript.bind_target(target);
ByteArrayOutputStream bytes = new ByteArrayOutputStream(Double.SIZE * dim);
DataOutputStream longs = new DataOutputStream(bytes);
long temp;
for(int i=0; i!=dim; ++i) {
temp = Double.doubleToLongBits(entries[i]);
// reverse byte order:
temp = Long.reverseBytes(temp);
longs.writeLong(temp);
}
target.copyFromUnchecked(bytes.toByteArray());
}
代码示例来源:origin: stackoverflow.com
public void copyDoublesTo(double[] entries, Allocation target) {
if (!target.getType().getElement().isCompatible(Element.F64(mRS))) {
throw new RSRuntimeException("Type mismatch: Element != F64");
}
if (target.getType().getCount() != entries.length) {
throw new RSRuntimeException("Type mismatch: wrong # of entries");
}
mScript.bind_target(target);
for(int i=0; i!=entries.length; ++i) {
mScript.invoke_setTargetEntry(i, entries[i]);
}
}
代码示例来源:origin: ApplikeySolutions/OrionPreview
public Bitmap blur(Context context, Bitmap image) {
int width = Math.round(image.getWidth() * BITMAP_SCALE);
int height = Math.round(image.getHeight() * BITMAP_SCALE);
Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
RenderScript rs = RenderScript.create(context);
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
theIntrinsic.setRadius(BLUR_RADIUS);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}
代码示例来源:origin: stackoverflow.com
final RenderScript rs = RenderScript.create( myAndroidContext );
final Allocation input = Allocation.createFromBitmap( rs, photo, 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( myBlurRadius /* e.g. 3.f */ );
script.setInput( input );
script.forEach( output );
output.copyTo( photo );
内容来源于网络,如有侵权,请联系作者删除!