本文整理汇总了Java中android.renderscript.Allocation.destroy方法的典型用法代码示例。如果您正苦于以下问题:Java Allocation.destroy方法的具体用法?Java Allocation.destroy怎么用?Java Allocation.destroy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.renderscript.Allocation
的用法示例。
在下文中一共展示了Allocation.destroy方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: if
import android.renderscript.Allocation; //导入方法依赖的package包/类
public static Bitmap 模糊(Bitmap $图片,int $半径) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Bitmap bitmap = $图片.copy($图片.getConfig(), true);
final RenderScript rs = RenderScript.create(上下文工具.取全局上下文());
final Allocation input = Allocation.createFromBitmap(rs, $图片, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius($半径);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
// clean up renderscript resources
rs.destroy();
input.destroy();
output.destroy();
script.destroy();
return bitmap;
}
return null;
}
示例2: generateShadow
import android.renderscript.Allocation; //导入方法依赖的package包/类
private void generateShadow() {
if (isJellyBeanAndAbove()) {
if (mShadowBlurRadius == 0f) return;
if (mShadow == null) {
mShadow = Bitmap.createBitmap(getWidth(), getHeight(), ALPHA_8);
} else {
mShadow.eraseColor(TRANSPARENT);
}
Canvas c = new Canvas(mShadow);
c.drawPath(mPath, mShadowPaint);
if (mShowBorder) {
c.drawPath(mPath, mShadowPaint);
}
RenderScript rs = RenderScript.create(getContext());
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8(rs));
Allocation input = Allocation.createFromBitmap(rs, mShadow);
Allocation output = Allocation.createTyped(rs, input.getType());
blur.setRadius(mShadowBlurRadius);
blur.setInput(input);
blur.forEach(output);
output.copyTo(mShadow);
input.destroy();
output.destroy();
}
}
示例3: blur
import android.renderscript.Allocation; //导入方法依赖的package包/类
/**
* @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;
}
示例4: apply
import android.renderscript.Allocation; //导入方法依赖的package包/类
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;
}
示例5: blurBitmap
import android.renderscript.Allocation; //导入方法依赖的package包/类
public Bitmap blurBitmap(float radius, float desaturateAmount) {
if (mSourceBitmap == null) {
return null;
}
Bitmap dest = mSourceBitmap.copy(mSourceBitmap.getConfig(), true);
if (radius == 0f && desaturateAmount == 0f) {
return dest;
}
Allocation allocationDest = Allocation.createFromBitmap(mRS, dest);
if (radius > 0f && desaturateAmount > 0f) {
doBlur(radius, mAllocationSrc, allocationDest);
doDesaturate(MathUtil.constrain(0, 1, desaturateAmount), allocationDest, mAllocationSrc);
mAllocationSrc.copyTo(dest);
} else if (radius > 0f) {
doBlur(radius, mAllocationSrc, allocationDest);
allocationDest.copyTo(dest);
} else {
doDesaturate(MathUtil.constrain(0, 1, desaturateAmount), mAllocationSrc, allocationDest);
allocationDest.copyTo(dest);
}
allocationDest.destroy();
return dest;
}
示例6: apply
import android.renderscript.Allocation; //导入方法依赖的package包/类
/**
* @param in
* @param out
* @return
*/
public Bitmap apply(Bitmap in, @Nullable Bitmap out) {
if (DO_TIMING) {
start = System.currentTimeMillis();
}
Allocation inAlloc = Allocation.createFromBitmap(rs, in);
Allocation outAlloc;
if (out != null) {
if (!sameSize(in, out)) {
throw new IllegalArgumentException(
"expected same sized bitmaps, got in=" + bitmapToString(in) + ", out=" +
bitmapToString(out));
}
outAlloc = Allocation.createFromBitmap(rs, out);
} else {
outAlloc = Allocation.createTyped(rs, inAlloc.getType());
}
Log.d(TAG, "applying RsRenderer: " + rsRenderer.getName());
rsRenderer.renderFrame(rs, inAlloc, outAlloc);
outAlloc.copyTo(out);
inAlloc.destroy();
outAlloc.destroy();
if (DO_TIMING) {
long duration = System.currentTimeMillis() - start;
Log.d(TAG, "applied RsRenderer: " + rsRenderer.getName() + " to " + bitmapToString(in) +
" (" + duration + " ms)");
}
return out;
}
示例7: fastBlur
import android.renderscript.Allocation; //导入方法依赖的package包/类
/**
* 使bitmap模糊化
*
* @param context
* @param bm
* @param radius
* @return
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap fastBlur(Context context, Bitmap bm, int radius) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Bitmap bitmap = bm.copy(bm.getConfig(), true);
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs,
bm, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs,
input.getType());
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs,
Element.U8_4(rs));
script.setRadius(radius);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
// clean up renderscript resources
rs.destroy();
input.destroy();
output.destroy();
script.destroy();
return bitmap;
}
return null;
}
示例8: blurBitmap
import android.renderscript.Allocation; //导入方法依赖的package包/类
private Bitmap blurBitmap(Bitmap original, float radius) {
Allocation overlayAllocation = null;
Allocation outAllocation = null;
ScriptIntrinsicBlur blur = null;
Bitmap result = null;
try {
if (renderScript == null) {
renderScript = RenderScript.create(LWQApplication.get());
}
overlayAllocation = Allocation.createFromBitmap(renderScript, original);
outAllocation = Allocation.createTyped(renderScript, overlayAllocation.getType());
result = Bitmap.createBitmap(original.getWidth(), original.getHeight(), original.getConfig());
blur = ScriptIntrinsicBlur.create(renderScript, overlayAllocation.getElement());
blur.setInput(overlayAllocation);
blur.setRadius(radius);
blur.forEach(outAllocation);
outAllocation.copyTo(result);
} finally {
if (renderScript != null) {
renderScript.destroy();
}
if (overlayAllocation != null) {
overlayAllocation.destroy();
}
if (outAllocation != null) {
outAllocation.destroy();
}
if (blur != null) {
blur.destroy();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
RenderScript.releaseAllContexts();
}
}
return result;
}
示例9: updateOriginalAllocation
import android.renderscript.Allocation; //导入方法依赖的package包/类
private synchronized boolean updateOriginalAllocation(ImagePreset preset) {
if (preset == null) {
return false;
}
Bitmap originalBitmap = mOriginalBitmap;
if (originalBitmap == null) {
return false;
}
RenderScript RS = getRenderScriptContext();
Allocation filtersOnlyOriginalAllocation = mFiltersOnlyOriginalAllocation;
mFiltersOnlyOriginalAllocation = Allocation.createFromBitmap(RS, originalBitmap,
Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
if (filtersOnlyOriginalAllocation != null) {
filtersOnlyOriginalAllocation.destroy();
}
Allocation originalAllocation = mOriginalAllocation;
mResizedOriginalBitmap = preset.applyGeometry(originalBitmap, mEnvironment);
mOriginalAllocation = Allocation.createFromBitmap(RS, mResizedOriginalBitmap,
Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
if (originalAllocation != null) {
originalAllocation.destroy();
}
return true;
}
示例10: blur
import android.renderscript.Allocation; //导入方法依赖的package包/类
@Override
public void blur(float radius, Bitmap in, Bitmap out) {
Allocation tmpIn = Allocation.createFromBitmap(rs, in);
Allocation tmpOut = Allocation.createFromBitmap(rs, out);
blur(radius, tmpIn, tmpOut);
tmpOut.copyTo(out);
tmpIn.destroy();
tmpOut.destroy();
}
示例11: renderScriptblur
import android.renderscript.Allocation; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap renderScriptblur(Context context, Bitmap origin, float scaledRatio, float radius) {
if (origin == null || origin.isRecycled()) return null;
radius = checkFloatRange(radius, 0, 20);
scaledRatio = checkFloatRange(scaledRatio, 0, 1);
final int originWidth = origin.getWidth();
final int originHeight = origin.getHeight();
PopupLogUtil.trace(LogTag.i, "originWidth >> " + originWidth + " originHeight >> " + originHeight);
int scaledWidth = originWidth;
int scaledHeight = originHeight;
if (scaledRatio > 0) {
scaledWidth = (int) (scaledWidth * scaledRatio);
scaledHeight = (int) (scaledHeight * scaledRatio);
}
PopupLogUtil.trace(LogTag.i, "scaledWidth >> " + scaledWidth + " scaledHeight >> " + scaledHeight);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(origin, scaledWidth, scaledHeight, false);
Bitmap result = Bitmap.createBitmap(scaledBitmap);
if (scaledBitmap.isRecycled() || result == null || result.isRecycled()) {
return null;
}
RenderScript renderScript = RenderScript.create(context);
Allocation blurInput = Allocation.createFromBitmap(renderScript, scaledBitmap);
Allocation blurOutput = Allocation.createFromBitmap(renderScript, result);
ScriptIntrinsicBlur blur = null;
try {
blur = ScriptIntrinsicBlur.create(renderScript, blurInput.getElement());
} catch (RSIllegalArgumentException e) {
if (e.getMessage().contains("Unsuported element type")) {
blur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
}
}
if (blur == null) return null;
blur.setRadius(radius);
blur.setInput(blurInput);
blur.forEach(blurOutput);
blurOutput.copyTo(result);
//释放
renderScript.destroy();
blurInput.destroy();
blurOutput.destroy();
scaledBitmap.recycle();
origin.recycle();
result = Bitmap.createScaledBitmap(result, originWidth, originHeight, false);
PopupLogUtil.trace(LogTag.i, "resultWidth >> " + result.getWidth() + " resultHeight >> " + result.getHeight());
return result;
}