本文整理匯總了Java中android.renderscript.ScriptIntrinsicBlur類的典型用法代碼示例。如果您正苦於以下問題:Java ScriptIntrinsicBlur類的具體用法?Java ScriptIntrinsicBlur怎麽用?Java ScriptIntrinsicBlur使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ScriptIntrinsicBlur類屬於android.renderscript包,在下文中一共展示了ScriptIntrinsicBlur類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: blurMax
import android.renderscript.ScriptIntrinsicBlur; //導入依賴的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.ScriptIntrinsicBlur; //導入依賴的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.ScriptIntrinsicBlur; //導入依賴的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.ScriptIntrinsicBlur; //導入依賴的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.ScriptIntrinsicBlur; //導入依賴的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.ScriptIntrinsicBlur; //導入依賴的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: if
import android.renderscript.ScriptIntrinsicBlur; //導入依賴的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;
}
示例8: createBlurredImageFromBitmap
import android.renderscript.ScriptIntrinsicBlur; //導入依賴的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);
}
示例9: transform
import android.renderscript.ScriptIntrinsicBlur; //導入依賴的package包/類
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
Bitmap blurredBitmap = toTransform.copy(Bitmap.Config.ARGB_8888, true);
Allocation input = Allocation.createFromBitmap(
rs,
blurredBitmap,
Allocation.MipmapControl.MIPMAP_FULL,
Allocation.USAGE_SHARED
);
Allocation output = Allocation.createTyped(rs, input.getType());
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setInput(input);
script.setRadius(15);
script.forEach(output);
output.copyTo(blurredBitmap);
toTransform.recycle();
return blurredBitmap;
}
示例10: renderScriptBlur
import android.renderscript.ScriptIntrinsicBlur; //導入依賴的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;
}
示例11: renderScriptBlur
import android.renderscript.ScriptIntrinsicBlur; //導入依賴的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, 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;
}
示例12: blur
import android.renderscript.ScriptIntrinsicBlur; //導入依賴的package包/類
public Bitmap blur(Bitmap image) {
if (null == image) return null;
Bitmap outputBitmap = Bitmap.createBitmap(image);
final RenderScript renderScript = RenderScript.create(this);
Allocation tmpIn = Allocation.createFromBitmap(renderScript, image);
Allocation tmpOut = Allocation.createFromBitmap(renderScript, outputBitmap);
//Intrinsic Gausian blur filter
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
theIntrinsic.setRadius(BLUR_RADIUS);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}
示例13: blurBitmap
import android.renderscript.ScriptIntrinsicBlur; //導入依賴的package包/類
/**
* 圖片高斯模糊
*
* @param context
* @param bitmap
* @return
*/
public static Bitmap blurBitmap(Context context, Bitmap bitmap) {
//用需要創建高斯模糊bitmap創建一個空的bitmap
Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
// 初始化Renderscript,該類提供了RenderScript context,創建其他RS類之前必須先創建這個類,其控製RenderScript的初始化,資源管理及釋放
RenderScript rs = RenderScript.create(context);
// 創建高斯模糊對象
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
// 創建Allocations,此類是將數據傳遞給RenderScript內核的主要方 法,並製定一個後備類型存儲給定類型
Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
//設定模糊度(注:Radius最大隻能設置25.f)
blurScript.setRadius(15f);
// Perform the Renderscript
blurScript.setInput(allIn);
blurScript.forEach(allOut);
allOut.copyTo(outBitmap);
rs.destroy();
return outBitmap;
}
示例14: renderScriptBlur
import android.renderscript.ScriptIntrinsicBlur; //導入依賴的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;
}
示例15: generateShadow
import android.renderscript.ScriptIntrinsicBlur; //導入依賴的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();
}
}