本文整理了Java中android.support.v8.renderscript.Allocation.createTyped()
方法的一些代码示例,展示了Allocation.createTyped()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Allocation.createTyped()
方法的具体详情如下:
包路径:android.support.v8.renderscript.Allocation
类名称:Allocation
方法名:createTyped
暂无
代码示例来源: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: north2016/T-MVP
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));
代码示例来源: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
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: 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: 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: zoff99/ToxAndroidRefImpl
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: googlecodelabs/android-workmanager
Allocation outAlloc = Allocation.createTyped(rsContext, inAlloc.getType());
ScriptIntrinsicBlur theIntrinsic =
ScriptIntrinsicBlur.create(rsContext, Element.U8_4(rsContext));
代码示例来源: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: woxingxiao/GracefulMovies
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));
代码示例来源: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: 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: 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);
}
内容来源于网络,如有侵权,请联系作者删除!