當前位置: 首頁>>代碼示例>>Java>>正文


Java RenderScript.create方法代碼示例

本文整理匯總了Java中android.support.v8.renderscript.RenderScript.create方法的典型用法代碼示例。如果您正苦於以下問題:Java RenderScript.create方法的具體用法?Java RenderScript.create怎麽用?Java RenderScript.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v8.renderscript.RenderScript的用法示例。


在下文中一共展示了RenderScript.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initialize

import android.support.v8.renderscript.RenderScript; //導入方法依賴的package包/類
/**
 * Initialize HeifReader module.
 *
 * @param context Context.
 */
public static void initialize(Context context) {
    mRenderScript = RenderScript.create(context);
    mCacheDir = context.getCacheDir();

    // find best HEVC decoder
    mDecoderName = null;
    mDecoderSupportedSize = new Size(0, 0);
    int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (codecInfo.isEncoder()) {
            continue;
        }
        for (String type : codecInfo.getSupportedTypes()) {
            if (type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_HEVC)) {
                MediaCodecInfo.CodecCapabilities cap = codecInfo.getCapabilitiesForType(MediaFormat.MIMETYPE_VIDEO_HEVC);
                MediaCodecInfo.VideoCapabilities vcap = cap.getVideoCapabilities();
                Size supportedSize = new Size(vcap.getSupportedWidths().getUpper(), vcap.getSupportedHeights().getUpper());
                Log.d(TAG, "HEVC decoder=\"" + codecInfo.getName() + "\""
                        + " supported-size=" + supportedSize
                        + " color-formats=" + Arrays.toString(cap.colorFormats)
                );
                if (mDecoderSupportedSize.getWidth() * mDecoderSupportedSize.getHeight() < supportedSize.getWidth() * supportedSize.getHeight()) {
                    mDecoderName = codecInfo.getName();
                    mDecoderSupportedSize = supportedSize;
                }
            }
        }
    }
    if (mDecoderName == null) {
        throw new RuntimeException("no HEVC decoding support");
    }
    Log.i(TAG, "HEVC decoder=\"" + mDecoderName + "\" supported-size=" + mDecoderSupportedSize);
}
 
開發者ID:yohhoy,項目名稱:heifreader,代碼行數:40,代碼來源:HeifReader.java

示例2: createBlurredImageFromBitmap

import android.support.v8.renderscript.RenderScript; //導入方法依賴的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 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);
    }
 
開發者ID:Vinetos,項目名稱:Hello-Music-droid,代碼行數:23,代碼來源:ImageUtils.java

示例3: blur

import android.support.v8.renderscript.RenderScript; //導入方法依賴的package包/類
public void blur(Bitmap originBitmap) {
    Bitmap scaledBitmap = Bitmap.createScaledBitmap(originBitmap, originBitmap.getWidth() / scaleRatio, originBitmap.getHeight() / scaleRatio, false);
    Bitmap mBitmapToBlur = scaledBitmap.copy(Bitmap.Config.ARGB_8888, true);
    Bitmap mBlurredBitmap = Bitmap.createBitmap(mBitmapToBlur.getWidth(), mBitmapToBlur.getHeight(),
            Bitmap.Config.ARGB_8888);

    mRenderScript = RenderScript.create(getContext());
    mBlurScript = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));

    mBlurInput = Allocation.createFromBitmap(mRenderScript, mBitmapToBlur,
            Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
    mBlurOutput = Allocation.createTyped(mRenderScript, mBlurInput.getType());

    mBlurInput.copyFrom(mBitmapToBlur);
    mBlurScript.setRadius(blurRadius);
    mBlurScript.setInput(mBlurInput);
    mBlurScript.forEach(mBlurOutput);
    mBlurOutput.copyTo(mBlurredBitmap);

    drawableFadeDisplayer.display(mBlurredBitmap, this);
    scaledBitmap.recycle();
    mBitmapToBlur.recycle();
    mRenderScript.destroy();
}
 
開發者ID:J1aDong,項目名稱:NetEaseMusicTransition-Android,代碼行數:25,代碼來源:BlurImageView.java

示例4: doBlur

import android.support.v8.renderscript.RenderScript; //導入方法依賴的package包/類
/**
 * blur a given bitmap
 *
 * @param sentBitmap       bitmap to blur
 * @param radius           blur radius
 * @param canReuseInBitmap true if bitmap must be reused without blur
 * @param context          used by RenderScript, can be null if RenderScript disabled
 * @return blurred bitmap
 */
public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap, Context context) {
    Bitmap bitmap;

    if (canReuseInBitmap) {
        bitmap = sentBitmap;
    } else {
        bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
    }

    if (bitmap.getConfig() == Bitmap.Config.RGB_565) {
        // RenderScript hates RGB_565 so we convert it to ARGB_8888
        // (see http://stackoverflow.com/questions/21563299/
        // defect-of-image-with-scriptintrinsicblur-from-support-library)
        bitmap = convertRGB565toARGB888(bitmap);
    }

    try {
        final RenderScript rs = RenderScript.create(context);
        final Allocation input = Allocation.createFromBitmap(rs, bitmap, 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);
        return bitmap;
    } catch (RSRuntimeException e) {
        Log.e(TAG, "RenderScript known error : https://code.google.com/p/android/issues/detail?id=71347 "
                + "continue with the FastBlur approach.");
    }

    return null;
}
 
開發者ID:RockyQu,項目名稱:MVVMFrames,代碼行數:44,代碼來源:BlurRenderScriptHelper.java

示例5: doBlur

import android.support.v8.renderscript.RenderScript; //導入方法依賴的package包/類
/**
 * blur a given bitmap
 *
 * @param sentBitmap       bitmap to blur
 * @param radius           blur radius
 * @param canReuseInBitmap true if bitmap must be reused without blur
 * @param context          used by RenderScript, can be null if RenderScript disabled
 * @return blurred bitmap
 */
public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap, Context context) {
    Bitmap bitmap;

    if (canReuseInBitmap) {
        bitmap = sentBitmap;
    } else {
        bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
    }

    if (bitmap.getConfig() == Bitmap.Config.RGB_565) {
        // RenderScript hates RGB_565 so we convert it to ARGB_8888
        // (see http://stackoverflow.com/questions/21563299/
        // defect-of-image-with-scriptintrinsicblur-from-support-library)
        bitmap = convertRGB565toARGB888(bitmap);
    }

    try {
        final RenderScript rs = RenderScript.create(context);
        final Allocation input = Allocation.createFromBitmap(rs, bitmap, 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);
        return bitmap;
    } catch (RSRuntimeException e) {
        Log.e(TAG, "RenderScript known error : https://code.google.com/p/android/issues/detail?id=71347 "
            + "continue with the FastBlur approach.");
    }

    return null;
}
 
開發者ID:zuoweitan,項目名稱:Hitalk,代碼行數:44,代碼來源:RenderScriptBlurHelper.java

示例6: getBlurBitmap

import android.support.v8.renderscript.RenderScript; //導入方法依賴的package包/類
@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;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:32,代碼來源:Blur.java

示例7: FastStyleModel

import android.support.v8.renderscript.RenderScript; //導入方法依賴的package包/類
public FastStyleModel(Context ctx) {
    mContext = ctx;
    mRS = RenderScript.create(ctx);
    mBlas = ScriptIntrinsicBLAS.create(mRS);
    mImg2Alloc = new ScriptC_img2alloc(mRS);
    mActivation = new ScriptC_activation(mRS);

    mConvLayer = new Convolution2D[3];
    mResidualLayer = new ResidualBlock[5];
    mDeconvLayer = new Deconvolution2D[3];
    mBatchNormLayer = new BatchNormalization[5];

    mConvLayer[0] = new Convolution2D(ctx, mRS, 3, 32, 9, 1, 4);
    mConvLayer[1] = new Convolution2D(ctx, mRS, 32, 64, 4, 2, 1);
    mConvLayer[2] = new Convolution2D(ctx, mRS, 64, 128, 4, 2, 1);

    mResidualLayer[0] = new ResidualBlock(ctx, mRS, 128, 128);
    mResidualLayer[1] = new ResidualBlock(ctx, mRS, 128, 128);
    mResidualLayer[2] = new ResidualBlock(ctx, mRS, 128, 128);
    mResidualLayer[3] = new ResidualBlock(ctx, mRS, 128, 128);
    mResidualLayer[4] = new ResidualBlock(ctx, mRS, 128, 128);

    mDeconvLayer[0] = new Deconvolution2D(ctx, mRS, 128, 64, 4, 2, 1);
    mDeconvLayer[1] = new Deconvolution2D(ctx, mRS, 64, 32, 4, 2, 1);
    mDeconvLayer[2] = new Deconvolution2D(ctx, mRS, 32, 3, 9, 1, 4);

    mBatchNormLayer[0] = new BatchNormalization(ctx, mRS, 32);
    mBatchNormLayer[1] = new BatchNormalization(ctx, mRS, 64);
    mBatchNormLayer[2] = new BatchNormalization(ctx, mRS, 128);
    mBatchNormLayer[3] = new BatchNormalization(ctx, mRS, 64);
    mBatchNormLayer[4] = new BatchNormalization(ctx, mRS, 32);
}
 
開發者ID:googlecodelabs,項目名稱:style-transfer,代碼行數:33,代碼來源:FastStyleModel.java

示例8: FastStyleModelTiled

import android.support.v8.renderscript.RenderScript; //導入方法依賴的package包/類
public FastStyleModelTiled(Context ctx) {
    mContext = ctx;

    mRS = RenderScript.create(ctx, Build.VERSION_CODES.LOLLIPOP);
    mBlas = ScriptIntrinsicBLAS.create(mRS);
    mImg2Alloc = new ScriptC_img2alloc(mRS);
    mActivation = new ScriptC_activation(mRS);

    mConvLayer = new Convolution2DTiled[3];
    mResidualLayer = new ResidualBlockChained(ctx, mRS, 128, 128, 3, 1, 1, 5);
    mDeconvLayer = new Deconvolution2DTiled[3];
    mBatchNormLayer = new BatchNormalization[5];

    mConvLayer[0] = new Convolution2DTiled(ctx, mRS, 3, 32, 9, 1, 4);
    mConvLayer[1] = new Convolution2DTiled(ctx, mRS, 32, 64, 4, 2, 1);
    mConvLayer[2] = new Convolution2DTiled(ctx, mRS, 64, 128, 4, 2, 1);

    mDeconvLayer[0] = new Deconvolution2DTiled(ctx, mRS, 128, 64, 4, 2, 1);
    mDeconvLayer[1] = new Deconvolution2DTiled(ctx, mRS, 64, 32, 4, 2, 1);
    mDeconvLayer[2] = new Deconvolution2DTiled(ctx, mRS, 32, 3, 9, 1, 4);

    mBatchNormLayer[0] = new BatchNormalization(ctx, mRS, 32);
    mBatchNormLayer[1] = new BatchNormalization(ctx, mRS, 64);
    mBatchNormLayer[2] = new BatchNormalization(ctx, mRS, 128);
    mBatchNormLayer[3] = new BatchNormalization(ctx, mRS, 64);
    mBatchNormLayer[4] = new BatchNormalization(ctx, mRS, 32);
}
 
開發者ID:googlecodelabs,項目名稱:style-transfer,代碼行數:28,代碼來源:FastStyleModelTiled.java

示例9: BlurArtwork

import android.support.v8.renderscript.RenderScript; //導入方法依賴的package包/類
public BlurArtwork(Context contexts, int radius, Bitmap bitmaps, ImageView imageView, int scale) {
    this.context = contexts;
    this.radius = radius;
    this.bitmap = bitmaps;
    this.imageView = imageView;
    renderScript = RenderScript.create(contexts);
}
 
開發者ID:RajneeshSingh007,項目名稱:MusicX-music-player,代碼行數:8,代碼來源:BlurArtwork.java

示例10: blurBitmap

import android.support.v8.renderscript.RenderScript; //導入方法依賴的package包/類
/**
 * 模糊圖片的具體方法
 *
 * @param context 上下文對象
 * @param image   需要模糊的圖片
 * @return 模糊處理後的圖片
 */
public static Bitmap blurBitmap(Context context, Bitmap image, float blurRadius) {
    // 計算圖片縮小後的長寬
    int width = Math.round(image.getWidth() * BITMAP_SCALE);
    int height = Math.round(image.getHeight() * BITMAP_SCALE);

    // 將縮小後的圖片做為預渲染的圖片
    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
    // 創建一張渲染後的輸出圖片
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

    // 創建RenderScript內核對象
    RenderScript rs = RenderScript.create(context);
    // 創建一個模糊效果的RenderScript的工具對象
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

    // 由於RenderScript並沒有使用VM來分配內存,所以需要使用Allocation類來創建和分配內存空間
    // 創建Allocation對象的時候其實內存是空的,需要使用copyTo()將數據填充進去
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);

    // 設置渲染的模糊程度, 25f是最大模糊度
    blurScript.setRadius(blurRadius);
    // 設置blurScript對象的輸入內存
    blurScript.setInput(tmpIn);
    // 將輸出數據保存到輸出內存中
    blurScript.forEach(tmpOut);

    // 將數據填充到Allocation中
    tmpOut.copyTo(outputBitmap);

    return outputBitmap;
}
 
開發者ID:ryanlijianchang,項目名稱:Recyclerview-Gallery,代碼行數:40,代碼來源:BlurBitmapUtil.java

示例11: getBlurBitmap

import android.support.v8.renderscript.RenderScript; //導入方法依賴的package包/類
@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;
}
 
開發者ID:uin3566,項目名稱:AllAngleExpandableButton,代碼行數:31,代碼來源:Blur.java

示例12: setUp

import android.support.v8.renderscript.RenderScript; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    super.setUp();
    setContext(context);
    createApplication();
    rs = RenderScript.create(getApplication());
}
 
開發者ID:silvaren,項目名稱:easyrs,代碼行數:8,代碼來源:ResizeTest.java

示例13: init

import android.support.v8.renderscript.RenderScript; //導入方法依賴的package包/類
public static void init(Context context)
{
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) new GraphicsHelper();
	else initSubstitutesForVariables();
	
	renderScript = RenderScript.create(context);
}
 
開發者ID:karol-202,項目名稱:PaintPlusPlus,代碼行數:8,代碼來源:GraphicsHelper.java

示例14: CustomLayout

import android.support.v8.renderscript.RenderScript; //導入方法依賴的package包/類
public CustomLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    mPaint.setColor(Color.WHITE);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(getResources().getDimensionPixelSize(R.dimen.stroke_width));
    mRenderScript = RenderScript.create(context);
    mIntrinsicBlur = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));
}
 
開發者ID:mattstraehl,項目名稱:AmgiNori,代碼行數:9,代碼來源:CustomLayout.java

示例15: blurRenderScript

import android.support.v8.renderscript.RenderScript; //導入方法依賴的package包/類
/**
 * StackBlur By Android RenderScript
 *
 * @param context          original context
 * @param original         Original Image
 * @param radius           Blur radius
 * @param canReuseInBitmap Can reuse In original Bitmap
 * @return Image Bitmap
 */
public static Bitmap blurRenderScript(Context context, Bitmap original, int radius, boolean canReuseInBitmap) {
    if (radius < 1) {
        return (null);
    }

    Bitmap bitmap = buildBitmap(original, canReuseInBitmap);

    // Return this none blur
    if (radius == 1) {
        return bitmap;
    }

    RenderScript rs = RenderScript.create(context);
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

    //Create the Allocations (in/out) with the Renderscript and the in/out bitmaps
    Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
    Allocation allOut = Allocation.createFromBitmap(rs, bitmap);

    //Set the radius of the blur: 0 < radius <= 25
    blurScript.setRadius(radius);

    //Perform the Renderscript
    blurScript.setInput(allIn);
    blurScript.forEach(allOut);

    //Copy the final bitmap created by the out Allocation to the outBitmap
    allOut.copyTo(bitmap);

    //recycle the original bitmap
    original.recycle();

    //After finishing everything, we destroy the Renderscript.
    rs.destroy();

    return bitmap;
}
 
開發者ID:jimmyxu0311,項目名稱:FastBlurBitmapUtils,代碼行數:47,代碼來源:FastBlur.java


注:本文中的android.support.v8.renderscript.RenderScript.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。