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


Java Allocation.createTyped方法代码示例

本文整理汇总了Java中android.renderscript.Allocation.createTyped方法的典型用法代码示例。如果您正苦于以下问题:Java Allocation.createTyped方法的具体用法?Java Allocation.createTyped怎么用?Java Allocation.createTyped使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.renderscript.Allocation的用法示例。


在下文中一共展示了Allocation.createTyped方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: blur

import android.renderscript.Allocation; //导入方法依赖的package包/类
public static Bitmap blur(Context context, Bitmap sentBitmap, int radius) {

        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
            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); //0.0f ~ 25.0f
            script.setInput(input);
            script.forEach(output);
            output.copyTo(bitmap);
            return bitmap;
        } else {
            return sentBitmap;
        }
    }
 
开发者ID:icaynia,项目名称:pracler,代码行数:20,代码来源:ImageUtils.java

示例2: renderScriptBlur

import android.renderscript.Allocation; //导入方法依赖的package包/类
/**
 * renderScript模糊图片
 * <p>API大于17</p>
 *
 * @param src     源图片
 * @param radius  模糊半径(0...25)
 * @return 模糊后的图片
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap renderScriptBlur(Bitmap src, @FloatRange(from = 0, to = 25, fromInclusive = false) float radius) {
    if (isEmptyBitmap(src)) return null;
    RenderScript rs = null;
    try {
        rs = RenderScript.create(Utils.getContext());
        rs.setMessageHandler(new RenderScript.RSMessageHandler());
        Allocation input = Allocation.createFromBitmap(rs, src, Allocation.MipmapControl.MIPMAP_NONE, Allocation
                .USAGE_SCRIPT);
        Allocation output = Allocation.createTyped(rs, input.getType());
        ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        blurScript.setInput(input);
        blurScript.setRadius(radius);
        blurScript.forEach(output);
        output.copyTo(src);
    } finally {
        if (rs != null) {
            rs.destroy();
        }
    }
    return src;
}
 
开发者ID:hoangkien0705,项目名称:Android-UtilCode,代码行数:31,代码来源:ImageUtils.java

示例3: twelve

import android.renderscript.Allocation; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap twelve(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final ScriptIntrinsicColorMatrix colorMatrix12 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix12.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    .309f, .409f, .309f, 0f,
                    .609f, .309f, .409f, 0f,
                    0.42f, .42f, .2f, 0f,
                    0f, 0f, 0f, 1f


            }));
    colorMatrix12.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
 
开发者ID:hgayan7,项目名称:FilterLibrary,代码行数:21,代码来源:PhotoFilter.java

示例4: 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

示例5: ten

import android.renderscript.Allocation; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap ten(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final   ScriptIntrinsicColorMatrix colorMatrix10 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix10.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    1f, 0f, 0.1f, -0.1f,
                    0f, 1f, 0.2f, 0f,
                    0f, 0f, 1.3f, 0f,
                    0f, 0f, 0f, 1

            }));
    colorMatrix10.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
 
开发者ID:hgayan7,项目名称:FilterLibrary,代码行数:20,代码来源:PhotoFilter.java

示例6: 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

示例7: createBlurredImageFromBitmap

import android.renderscript.Allocation; //导入方法依赖的package包/类
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 Allocation input = Allocation.createFromBitmap(rs, blurTemplate);
        final Allocation output = Allocation.createTyped(rs, input.getType());
        final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        script.setRadius(8f);
        script.setInput(input);
        script.forEach(output);
        output.copyTo(blurTemplate);

        return new BitmapDrawable(context.getResources(), blurTemplate);
    }
 
开发者ID:komamj,项目名称:KomaMusic,代码行数:23,代码来源:ImageLoader.java

示例8: blurBitmap

import android.renderscript.Allocation; //导入方法依赖的package包/类
public static Bitmap blurBitmap(Context context, Bitmap bmp, float radius) {
    Bitmap out = Bitmap.createBitmap(bmp);
    RenderScript rs = RenderScript.create(context);
    radius = Math.min(Math.max(radius, 0), 25);

    Allocation input = Allocation.createFromBitmap(
            rs, bmp, MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
    Allocation output = Allocation.createTyped(rs, input.getType());

    ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    script.setInput(input);
    script.setRadius(radius);
    script.forEach(output);

    output.copyTo(out);

    rs.destroy();
    return out;
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:20,代码来源:Utils.java

示例9: renderScriptBlur

import android.renderscript.Allocation; //导入方法依赖的package包/类
/**
 * renderScript模糊图片
 * <p>API大于17</p>
 *
 * @param src    源图片
 * @param radius 模糊半径(0...25)
 * @return 模糊后的图片
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap renderScriptBlur(Bitmap src, @FloatRange(from = 0, to = 25, fromInclusive = false) float radius) {
    if (isEmptyBitmap(src)) return null;
    RenderScript rs = null;
    try {
        rs = RenderScript.create(Utils.getContext());
        rs.setMessageHandler(new RenderScript.RSMessageHandler());
        Allocation input = Allocation.createFromBitmap(rs, src, Allocation.MipmapControl.MIPMAP_NONE, Allocation
                .USAGE_SCRIPT);
        Allocation output = Allocation.createTyped(rs, input.getType());
        ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        blurScript.setInput(input);
        blurScript.setRadius(radius);
        blurScript.forEach(output);
        output.copyTo(src);
    } finally {
        if (rs != null) {
            rs.destroy();
        }
    }
    return src;
}
 
开发者ID:pan2yong22,项目名称:AndroidUtilCode-master,代码行数:31,代码来源:ImageUtils.java

示例10: eleven

import android.renderscript.Allocation; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap eleven(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final   ScriptIntrinsicColorMatrix colorMatrix11 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix11.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    1.72814708519562f, -0.412104992562475f, 0.541145007437525f, 0f,
                    0.289378264402959f, 1.18835534216106f, -1.17637173559704f, 0f,
                    -1.01752534959858f, 0.223749650401417f, 1.63522672815952f, 0f,
                    0f, 0f, 0f, 1f


            }));
    colorMatrix11.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
 
开发者ID:hgayan7,项目名称:FilterLibrary,代码行数:21,代码来源:PhotoFilter.java

示例11: four

import android.renderscript.Allocation; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap four(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final ScriptIntrinsicColorMatrix colorMatrix4 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix4.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    0.3f, 0f, 0f, 0f,
                    0f, 0.65f, 0f, 0f,
                    0f, 0f, 0.49f, 0f,
                    0f, 0f, 0f, 1f


            }));
    colorMatrix4.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
 
开发者ID:hgayan7,项目名称:FilterLibrary,代码行数:21,代码来源:PhotoFilter.java

示例12: blurBitmap

import android.renderscript.Allocation; //导入方法依赖的package包/类
@Nullable
public static Bitmap blurBitmap(Context context, Bitmap bitmap) {
    if (context == null || bitmap == null) return null;

    Bitmap blurredBitmap;
    try {
        blurredBitmap = Bitmap.createBitmap(bitmap);
    } catch (OutOfMemoryError e) {
        return null;
    }

    RenderScript renderScript = RenderScript.create(context);
    Allocation input = Allocation.createFromBitmap(renderScript, bitmap, 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(20);

    script.forEach(output);
    output.copyTo(blurredBitmap);

    return blurredBitmap;
}
 
开发者ID:TheAndroidMaster,项目名称:Bagels,代码行数:25,代码来源:ImageUtils.java

示例13: transform

import android.renderscript.Allocation; //导入方法依赖的package包/类
@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(25);

    // Start the ScriptIntrinisicBlur
    script.forEach(output);

    // Copy the output to the blurred bitmap
    output.copyTo(blurredBitmap);

    return blurredBitmap;
}
 
开发者ID:salRoid,项目名称:Clasick,代码行数:25,代码来源:BlurTransform.java

示例14: renderScriptBlur

import android.renderscript.Allocation; //导入方法依赖的package包/类
/**
 * renderScript模糊图片
 * <p>API大于17</p>
 *
 * @param src     源图片
 * @param radius  模糊半径(0...25)
 * @param recycle 是否回收
 * @return 模糊后的图片
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap renderScriptBlur(final Bitmap src,
                                      @FloatRange(from = 0, to = 25, fromInclusive = false) final float radius,
                                      final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    RenderScript rs = null;
    Bitmap ret = recycle ? src : src.copy(src.getConfig(), true);
    try {
        rs = RenderScript.create(SDAndroidLib.getContext());
        rs.setMessageHandler(new RenderScript.RSMessageHandler());
        Allocation input = Allocation.createFromBitmap(rs, ret, Allocation.MipmapControl.MIPMAP_NONE, Allocation
                .USAGE_SCRIPT);
        Allocation output = Allocation.createTyped(rs, input.getType());
        ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        blurScript.setInput(input);
        blurScript.setRadius(radius);
        blurScript.forEach(output);
        output.copyTo(ret);
    } finally {
        if (rs != null) {
            rs.destroy();
        }
    }
    return ret;
}
 
开发者ID:SiberiaDante,项目名称:AndroidUtilLib,代码行数:35,代码来源:SDBitmapUtil.java

示例15: 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


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