當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。