本文整理了Java中android.support.v8.renderscript.Allocation
类的一些代码示例,展示了Allocation
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Allocation
类的具体详情如下:
包路径:android.support.v8.renderscript.Allocation
类名称:Allocation
暂无
代码示例来源: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: 500px/500px-android-blur
protected void blur() {
mBlurInput.copyFrom(mBitmapToBlur);
mBlurScript.setInput(mBlurInput);
mBlurScript.forEach(mBlurOutput);
mBlurOutput.copyTo(mBlurredBitmap);
}
代码示例来源:origin: 500px/500px-android-blur
mBlurInput = Allocation.createFromBitmap(mRenderScript, mBitmapToBlur,
Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
mBlurOutput = Allocation.createTyped(mRenderScript, mBlurInput.getType());
代码示例来源:origin: huazhiyuan2008/RecyclerViewCardGallery
Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
tmpOut.copyTo(outputBitmap);
代码示例来源:origin: SmartDengg/RxBlur
mTmp1.destroy();
mTmp2.destroy();
} catch (RSInvalidStateException e) {
mTmp1 = Allocation.createFromBitmap(mRS, src);
mTmp2 = Allocation.createFromBitmap(mRS, dest);
mTmp1.copyTo(dest);
} else if (radius > 0f) {
doBlur(radius, mTmp1, mTmp2);
mTmp2.copyTo(dest);
} else {
doDesaturate(MathUtil.constrain(0, 1, desaturateAmount), mTmp1, mTmp2);
mTmp2.copyTo(dest);
代码示例来源: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: mmin18/RealtimeBlurView
private void releaseBitmap() {
if (mBlurInput != null) {
mBlurInput.destroy();
mBlurInput = null;
}
if (mBlurOutput != null) {
mBlurOutput.destroy();
mBlurOutput = null;
}
if (mBitmapToBlur != null) {
mBitmapToBlur.recycle();
mBitmapToBlur = null;
}
if (mBlurredBitmap != null) {
mBlurredBitmap.recycle();
mBlurredBitmap = null;
}
}
代码示例来源: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: mmin18/RealtimeBlurView
mBlurInput = Allocation.createFromBitmap(mRenderScript, mBitmapToBlur,
Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
mBlurOutput = Allocation.createTyped(mRenderScript, mBlurInput.getType());
代码示例来源: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: Dimezis/BlurView
@Override
public final void destroy() {
blurScript.destroy();
renderScript.destroy();
if (outAllocation != null) {
outAllocation.destroy();
}
}
代码示例来源: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: 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: mmin18/RealtimeBlurView
protected void blur(Bitmap bitmapToBlur, Bitmap blurredBitmap) {
mBlurInput.copyFrom(bitmapToBlur);
mBlurScript.setInput(mBlurInput);
mBlurScript.forEach(mBlurOutput);
mBlurOutput.copyTo(blurredBitmap);
}
代码示例来源:origin: SmartDengg/RxBlur
public void destroy() {
mSIBlur.destroy();
if (mTmp1 != null) {
mTmp1.destroy();
}
if (mTmp2 != null) {
mTmp2.destroy();
}
mRS.destroy();
}
}
代码示例来源: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: f2prateek/device-frame-generator
Allocation allIn = Allocation.createFromBitmap(renderScript, croppedScreenshot);
Allocation allOut = Allocation.createFromBitmap(renderScript, blurredScreenshot);
allOut.copyTo(blurredScreenshot);
代码示例来源:origin: zoff99/ToxAndroidRefImpl
alloc_in.copyFrom(video_buffer_1.array());
yuvToRgb.setInput(alloc_in);
yuvToRgb.forEach(alloc_out);
alloc_out.copyTo(video_frame_image);
代码示例来源: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));
blur.setRadius(mRadius);
blur.forEach(output);
output.copyTo(bitmap);
代码示例来源: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;
}
内容来源于网络,如有侵权,请联系作者删除!