本文整理汇总了Java中android.renderscript.RenderScript类的典型用法代码示例。如果您正苦于以下问题:Java RenderScript类的具体用法?Java RenderScript怎么用?Java RenderScript使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RenderScript类属于android.renderscript包,在下文中一共展示了RenderScript类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: blurMax
import android.renderscript.RenderScript; //导入依赖的package包/类
public static Bitmap blurMax(Context context, Bitmap image) {
// 计算图片缩小后的长宽
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(25f);
// 设置blurScript对象的输入内存
blurScript.setInput(tmpIn);
// 将输出数据保存到输出内存中
blurScript.forEach(tmpOut);
// 将数据填充到Allocation中
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}
示例2: blur
import android.renderscript.RenderScript; //导入依赖的package包/类
private static Bitmap blur(Context context, Bitmap image) {
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 rs = RenderScript.create(context);
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
theIntrinsic.setRadius(BLUR_RADIUS);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}
示例3: renderScriptBlur
import android.renderscript.RenderScript; //导入依赖的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(Utils.getApp());
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;
}
示例4: blur
import android.renderscript.RenderScript; //导入依赖的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;
}
}
示例5: blur
import android.renderscript.RenderScript; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap blur(UQI uqi, Bitmap image) {
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 rs = RenderScript.create(uqi.getContext());
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
theIntrinsic.setRadius(BLUR_RADIUS);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}
示例6: renderScriptBlur
import android.renderscript.RenderScript; //导入依赖的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;
}
示例7: renderFrame
import android.renderscript.RenderScript; //导入依赖的package包/类
@Override
public void renderFrame(RenderScript rs, Allocation in, Allocation out) {
if (blendScript == null) {
blendScript = ScriptIntrinsicBlend.create(rs, in.getElement());
setAlphaScript = new ScriptC_set_alpha(rs);
last = RsUtil.createMatchingAlloc(rs, in);
last.copyFrom(in);
}
out.copyFrom(last);
// setting the alpha here is just to trick ScriptIntrinsicBlend to do linear
// interpolation for us
setAlphaScript.set_alpha_value((short) 200);
setAlphaScript.forEach_filter(out, out);
setAlphaScript.set_alpha_value((short) 55);
setAlphaScript.forEach_filter(in, in);
blendScript.forEachSrcAtop(in, out);
last.copyFrom(out);
}
示例8: renderFrame
import android.renderscript.RenderScript; //导入依赖的package包/类
@Override
public void renderFrame(RenderScript rs, Allocation in, Allocation out) {
if (resizeRsRenderer == null) {
resizeRsRenderer = new ResizeRsRenderer();
colorFrameScript = new ScriptC_color_frame(rs);
scaledAlloc = RsUtil.createRgbAlloc(rs, RsUtil.width(in) / 2, RsUtil.height(in) / 2);
colorFrameScript.invoke_prepare(scaledAlloc);
}
if (count++ % FRAMES_BEFORE_COLOR_REFRESH == 0) {
loadRandomRGBAColor();
colorFrameScript.set_color(rgbaColor);
}
// scale image
resizeRsRenderer.renderFrame(rs, in, scaledAlloc);
// draw scaled image and color frame. we use out as input and output because we don't
// actually use the input value in the calculation, just the rectangle bounds
colorFrameScript.forEach_frame_image(out, out);
}
示例9: if
import android.renderscript.RenderScript; //导入依赖的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;
}
示例10: createBlurredImageFromBitmap
import android.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 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);
}
示例11: renderScriptBlur
import android.renderscript.RenderScript; //导入依赖的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;
}
示例12: one
import android.renderscript.RenderScript; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap one(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 colorMatrix1=ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
colorMatrix1.setColorMatrix(new android.renderscript.Matrix4f(new float[]
{
-0.33f, -0.33f, -0.33f, 1.0f,
-0.59f, -0.59f, -0.59f, 1.0f,
-0.11f, -0.11f, -0.11f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f
}));
colorMatrix1.forEach(inputAllocation,outputAllocation);
outputAllocation.copyTo(outBitmap);
return outBitmap;
}
示例13: three
import android.renderscript.RenderScript; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap three(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 colorMatrix3 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
colorMatrix3.setColorMatrix(new android.renderscript.Matrix4f(new float[]
{
0f, 0f, 0f, 0f,
0f, 0.78f, 0f, 0f,
0f, 0f, 1f, 0f,
0f, 0f, 0f, 1f,
}));
colorMatrix3.forEach(inputAllocation, outputAllocation);
outputAllocation.copyTo(outBitmap);
return outBitmap;
}
示例14: four
import android.renderscript.RenderScript; //导入依赖的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;
}
示例15: five
import android.renderscript.RenderScript; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap five(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 colorMatrix5 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
colorMatrix5.setColorMatrix(new android.renderscript.Matrix4f(new float[]
{
-0.359705309629158f, 0.377252728606377f, 0.663841667303255f, 0f,
1.56680818833214f, 0.456668209492391f, 1.12613917506705f, 0f,
-0.147102878702981f, 0.226079061901232f, -0.729980842370303f, 0f,
0f, 0f, 0f, 1f
}));
colorMatrix5.forEach(inputAllocation, outputAllocation);
outputAllocation.copyTo(outBitmap);
return outBitmap;
}