本文整理汇总了Java中android.renderscript.Allocation.createFromBitmap方法的典型用法代码示例。如果您正苦于以下问题:Java Allocation.createFromBitmap方法的具体用法?Java Allocation.createFromBitmap怎么用?Java Allocation.createFromBitmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.renderscript.Allocation
的用法示例。
在下文中一共展示了Allocation.createFromBitmap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: blur
import android.renderscript.Allocation; //导入方法依赖的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;
}
示例2: 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(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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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);
}
示例6: fourteen
import android.renderscript.Allocation; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap fourteen(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 ScriptIntrinsicConvolve3x3 convolve2 = ScriptIntrinsicConvolve3x3.create(renderScript, Element.U8_4(renderScript));
convolve2.setInput(inputAllocation);
convolve2.setCoefficients(new float[]
{
.2f, .3f, .2f, .1f, .1f, .1f, .2f, .3f, .2f,
});
convolve2.forEach(outputAllocation);
outputAllocation.copyTo(outBitmap);
return outBitmap;
}
示例7: sixteen
import android.renderscript.Allocation; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap sixteen(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 colorMatrix14 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
colorMatrix14.setColorMatrix(new android.renderscript.Matrix4f(new float[]
{
1.27488526960083f, -0.228511311848763f, 0.441088688151237f, 0,
0.323664244263542f, 0.955140825713134f, -0.705935755736458f, 0,
-0.698549513864371f, 0.173370486135629f , 1.16484706758522f ,0,
0,0,0,1
}));
colorMatrix14.forEach(inputAllocation, outputAllocation);
outputAllocation.copyTo(outBitmap);
return outBitmap;
}
示例8: renderScriptBlur
import android.renderscript.Allocation; //导入方法依赖的package包/类
/**
* renderScript模糊图片
* <p>API大于17</p>
*
* @param context 上下文
* @param src 源图片
* @param radius 模糊半径(0...25)
* @return 模糊后的图片
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap renderScriptBlur(Context context, Bitmap src, @FloatRange(from = 0, to = 25, fromInclusive = false) float radius) {
if (isEmptyBitmap(src)) {
return null;
}
RenderScript rs = null;
try {
rs = RenderScript.create(context);
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;
}
示例9: rsBlur
import android.renderscript.Allocation; //导入方法依赖的package包/类
public static Bitmap rsBlur(Context context, Bitmap source, int radius) {
// 计算图片缩小后的长宽
int width = Math.round(source.getWidth() * BITMAP_SCALE);
int height = Math.round(source.getHeight() * BITMAP_SCALE);
// 将缩小后的图片做为预渲染的图片
Bitmap inputBitmap = Bitmap.createScaledBitmap(source, width, height, false);
RenderScript renderScript = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(renderScript, inputBitmap);
final Allocation outPut = Allocation.createTyped(renderScript, input.getType());
ScriptIntrinsicBlur scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript,
Element.U8_4(renderScript));
scriptIntrinsicBlur.setInput(input);
scriptIntrinsicBlur.setRadius(radius);
scriptIntrinsicBlur.forEach(outPut);
outPut.copyTo(inputBitmap);
renderScript.destroy();
return inputBitmap;
}
示例10: three
import android.renderscript.Allocation; //导入方法依赖的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;
}
示例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;
}
示例12: five
import android.renderscript.Allocation; //导入方法依赖的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;
}
示例13: six
import android.renderscript.Allocation; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap six(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 colorMatrix6 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
colorMatrix6.setColorMatrix(new android.renderscript.Matrix4f(new float[]
{
1.2f, 0.1f, 0.2f, 0.7f,
0.7f, 1f, 0f, -0.5f,
-0.7f, 0.2f, 0.5f, 1.3f,
0, -0.1f, 0f, 0.9f
}));
colorMatrix6.forEach(inputAllocation, outputAllocation);
outputAllocation.copyTo(outBitmap);
return outBitmap;
}
示例14: 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;
}
示例15: blur
import android.renderscript.Allocation; //导入方法依赖的package包/类
public Bitmap blur(Context context, Bitmap image,float radius) {
int width = Math.round(image.getWidth() * 1.0f);
int height = Math.round(image.getHeight() * 1.0f);
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(radius);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}