本文整理汇总了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);
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例12: setUp
import android.support.v8.renderscript.RenderScript; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
super.setUp();
setContext(context);
createApplication();
rs = RenderScript.create(getApplication());
}
示例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);
}
示例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));
}
示例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;
}