当前位置: 首页>>代码示例>>Java>>正文


Java Allocation.destroy方法代码示例

本文整理汇总了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;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:23,代码来源:图片工具.java

示例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();
    }
}
 
开发者ID:vipulasri,项目名称:TicketView,代码行数:27,代码来源:TicketView.java

示例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;
}
 
开发者ID:Dimezis,项目名称:BlurView,代码行数:30,代码来源:RenderScriptBlur.java

示例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;
}
 
开发者ID:wingjay,项目名称:jayAndroid,代码行数:21,代码来源:RenderScriptBlur.java

示例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;
}
 
开发者ID:romannurik,项目名称:muzei,代码行数:27,代码来源:ImageBlurrer.java

示例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;
}
 
开发者ID:lydia-schiff,项目名称:hella-renderscript,代码行数:40,代码来源:RsBitmapRenderer.java

示例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;
}
 
开发者ID:venshine,项目名称:AndroidCommon,代码行数:36,代码来源:BlurUtils.java

示例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;
}
 
开发者ID:stanidesis,项目名称:quotograph,代码行数:37,代码来源:LWQDrawScript.java

示例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;
}
 
开发者ID:asm-products,项目名称:nexus-gallery,代码行数:30,代码来源:CachingPipeline.java

示例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();
}
 
开发者ID:xuchdeid,项目名称:LiveBlurListView,代码行数:10,代码来源:RSRender.java

示例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;
}
 
开发者ID:razerdp,项目名称:BasePopup,代码行数:59,代码来源:BlurHelper.java


注:本文中的android.renderscript.Allocation.destroy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。