android.renderscript.RSRuntimeException Java Examples
The following examples show how to use
android.renderscript.RSRuntimeException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlurTransformation.java From AcgClub with MIT License | 5 votes |
private Bitmap doBlur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException { RenderScript rs = null; Allocation input = null; Allocation output = null; ScriptIntrinsicBlur blur = null; try { rs = RenderScript.create(context); rs.setMessageHandler(new RenderScript.RSMessageHandler()); input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); output = Allocation.createTyped(rs, input.getType()); blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); blur.setInput(input); blur.setRadius(radius); blur.forEach(output); output.copyTo(bitmap); } finally { if (rs != null) { rs.destroy(); } if (input != null) { input.destroy(); } if (output != null) { output.destroy(); } if (blur != null) { blur.destroy(); } } return bitmap; }
Example #2
Source File: BlurTransformation.java From picasso-transformations with Apache License 2.0 | 5 votes |
@Override public Bitmap transform(Bitmap source) { int scaledWidth = source.getWidth() / mSampling; int scaledHeight = source.getHeight() / mSampling; Bitmap bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) mSampling, 1 / (float) mSampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(source, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { bitmap = RSBlur.blur(mContext, bitmap, mRadius); } catch (RSRuntimeException e) { bitmap = FastBlur.blur(bitmap, mRadius, true); } } else { bitmap = FastBlur.blur(bitmap, mRadius, true); } source.recycle(); return bitmap; }
Example #3
Source File: Blur.java From MyBlogDemo with Apache License 2.0 | 5 votes |
public static Bitmap of(Context context, Bitmap source, BlurFactor factor) { int width = factor.width / factor.sampling; int height = factor.height / factor.sampling; if (Helper.hasZero(width, height)) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) factor.sampling, 1 / (float) factor.sampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG); PorterDuffColorFilter filter = new PorterDuffColorFilter(factor.color, PorterDuff.Mode.SRC_ATOP); paint.setColorFilter(filter); canvas.drawBitmap(source, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { bitmap = Blur.rs(context, bitmap, factor.radius); } catch (RSRuntimeException e) { bitmap = Blur.stack(bitmap, factor.radius, true); } } else { bitmap = Blur.stack(bitmap, factor.radius, true); } if (factor.sampling == BlurFactor.DEFAULT_SAMPLING) { return bitmap; } else { Bitmap scaled = Bitmap.createScaledBitmap(bitmap, factor.width, factor.height, true); bitmap.recycle(); return scaled; } }
Example #4
Source File: Blur.java From Blurry with Apache License 2.0 | 5 votes |
public static Bitmap of(Context context, Bitmap source, BlurFactor factor) { int width = factor.width / factor.sampling; int height = factor.height / factor.sampling; if (Helper.hasZero(width, height)) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) factor.sampling, 1 / (float) factor.sampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG); PorterDuffColorFilter filter = new PorterDuffColorFilter(factor.color, PorterDuff.Mode.SRC_ATOP); paint.setColorFilter(filter); canvas.drawBitmap(source, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { bitmap = Blur.rs(context, bitmap, factor.radius); } catch (RSRuntimeException e) { bitmap = Blur.stack(bitmap, factor.radius, true); } } else { bitmap = Blur.stack(bitmap, factor.radius, true); } if (factor.sampling == BlurFactor.DEFAULT_SAMPLING) { return bitmap; } else { Bitmap scaled = Bitmap.createScaledBitmap(bitmap, factor.width, factor.height, true); bitmap.recycle(); return scaled; } }
Example #5
Source File: BlurTransformation.java From FamilyChat with Apache License 2.0 | 5 votes |
@Override public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { Bitmap source = resource.get(); int width = source.getWidth(); int height = source.getHeight(); int scaledWidth = width / mSampling; int scaledHeight = height / mSampling; Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); if (bitmap == null) { bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) mSampling, 1 / (float) mSampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(source, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { bitmap = RSBlur.blur(mContext, bitmap, mRadius); } catch (RSRuntimeException e) { bitmap = FastBlur.blur(bitmap, mRadius, true); } } else { bitmap = FastBlur.blur(bitmap, mRadius, true); } return BitmapResource.obtain(bitmap, mBitmapPool); }
Example #6
Source File: Blur.java From likequanmintv with Apache License 2.0 | 5 votes |
public static Bitmap of(Context context, Bitmap source, BlurFactor factor) { int width = factor.width / factor.sampling; int height = factor.height / factor.sampling; if (Helper.hasZero(width, height)) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) factor.sampling, 1 / (float) factor.sampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG); PorterDuffColorFilter filter = new PorterDuffColorFilter(factor.color, PorterDuff.Mode.SRC_ATOP); paint.setColorFilter(filter); canvas.drawBitmap(source, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { bitmap = Blur.rs(context, bitmap, factor.radius); } catch (RSRuntimeException e) { bitmap = Blur.stack(bitmap, factor.radius, true); } } else { bitmap = Blur.stack(bitmap, factor.radius, true); } if (factor.sampling == BlurFactor.DEFAULT_SAMPLING) { return bitmap; } else { Bitmap scaled = Bitmap.createScaledBitmap(bitmap, factor.width, factor.height, true); bitmap.recycle(); return scaled; } }
Example #7
Source File: BlurTransformation.java From DismissibleImageView with Apache License 2.0 | 5 votes |
@Override public Bitmap transform(Bitmap source) { int scaledWidth = source.getWidth() / mSampling; int scaledHeight = source.getHeight() / mSampling; Bitmap bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) mSampling, 1 / (float) mSampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(source, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { bitmap = RsBlur.blur(mContext, bitmap, mRadius); } catch (RSRuntimeException e) { bitmap = FastBlur.blur(bitmap, mRadius, true); } } else { bitmap = FastBlur.blur(bitmap, mRadius, true); } //source.recycle(); return bitmap; }
Example #8
Source File: BlurTransformation.java From AccountBook with GNU General Public License v3.0 | 5 votes |
@Override public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { Bitmap source = resource.get(); int width = source.getWidth(); int height = source.getHeight(); int scaledWidth = width / mSampling; int scaledHeight = height / mSampling; Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); if (bitmap == null) { bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) mSampling, 1 / (float) mSampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(source, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { bitmap = RSBlur.blur(mContext, bitmap, mRadius); } catch (RSRuntimeException e) { bitmap = FastBlur.blur(bitmap, mRadius, true); } } else { bitmap = FastBlur.blur(bitmap, mRadius, true); } return BitmapResource.obtain(bitmap, mBitmapPool); }
Example #9
Source File: Glide4Loader.java From ImageLoader with Apache License 2.0 | 5 votes |
public static Bitmap blur(Bitmap source,int mRadius,boolean recycleOriginal){ int mSampling = 1; int width = source.getWidth(); int height = source.getHeight(); int scaledWidth = width / mSampling; int scaledHeight = height / mSampling; Bitmap bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) mSampling, 1 / (float) mSampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(source, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { bitmap = RSBlur.blur(ImageLoader.context, bitmap, mRadius); } catch (RSRuntimeException e) { bitmap = FastBlur.blur(bitmap, mRadius, true); } } else { bitmap = FastBlur.blur(bitmap, mRadius, true); } if(recycleOriginal){ source.recycle(); } return bitmap; }
Example #10
Source File: FrescoLoader.java From ImageLoader with Apache License 2.0 | 5 votes |
public static Bitmap blur(Bitmap source,int mRadius,boolean recycleOriginal){ int mSampling = 2; int width = source.getWidth(); int height = source.getHeight(); int scaledWidth = width / mSampling; int scaledHeight = height / mSampling; Bitmap bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, source.getConfig()); Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) mSampling, 1 / (float) mSampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(source, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { bitmap = RSBlur.blur(ImageLoader.context, bitmap, mRadius); } catch (RSRuntimeException e) { bitmap = FastBlur.blur(bitmap, mRadius, true); } } else { bitmap = FastBlur.blur(bitmap, mRadius, true); } if(recycleOriginal){ source.recycle(); } return bitmap; }
Example #11
Source File: GlideLoader.java From ImageLoader with Apache License 2.0 | 5 votes |
public static Bitmap blur(Bitmap source,int mRadius,boolean recycleOriginal){ int mSampling = 1; int width = source.getWidth(); int height = source.getHeight(); int scaledWidth = width / mSampling; int scaledHeight = height / mSampling; Bitmap bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) mSampling, 1 / (float) mSampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(source, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { bitmap = RSBlur.blur(ImageLoader.context, bitmap, mRadius); } catch (RSRuntimeException e) { bitmap = FastBlur.blur(bitmap, mRadius, true); } } else { bitmap = FastBlur.blur(bitmap, mRadius, true); } if(recycleOriginal){ source.recycle(); } return bitmap; }
Example #12
Source File: BlurTransform.java From ImageLoader with Apache License 2.0 | 5 votes |
@Override public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { Bitmap source = resource.get(); int width = source.getWidth(); int height = source.getHeight(); int samplesize = MyUtil.calculateScaleRatio(width,height,outWidth,outHeight,subsamplingRatio); int scaledWidth = width / samplesize; int scaledHeight = height / samplesize; Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); if (bitmap == null) { bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) samplesize, 1 / (float) samplesize); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(source, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { bitmap = RSBlur.blur(mContext, bitmap, mRadius); } catch (RSRuntimeException e) { bitmap = FastBlur.blur(bitmap, mRadius, true); } } else { bitmap = FastBlur.blur(bitmap, mRadius, true); } return BitmapResource.obtain(bitmap, mBitmapPool); }
Example #13
Source File: BlurTransformation.java From TestChat with Apache License 2.0 | 5 votes |
@Override public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { Bitmap source = resource.get(); int width = source.getWidth(); int height = source.getHeight(); int scaledWidth = width / mSampling; int scaledHeight = height / mSampling; Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); if (bitmap == null) { bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) mSampling, 1 / (float) mSampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(source, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { try { bitmap = RSBlur.blur(mContext, bitmap, mRadius); } catch (RSRuntimeException e) { bitmap = FastBlur.blur(bitmap, mRadius, true); } } else { bitmap = FastBlur.blur(bitmap, mRadius, true); } return BitmapResource.obtain(bitmap, mBitmapPool); }
Example #14
Source File: AFGlideUtil.java From AFBaseLibrary with Apache License 2.0 | 5 votes |
@Override public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { Bitmap source = resource.get(); int width = source.getWidth(); int height = source.getHeight(); int scaledWidth = width / mSampling; int scaledHeight = height / mSampling; Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); if (bitmap == null) { bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) mSampling, 1 / (float) mSampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(source, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { bitmap = blur(mContext, bitmap, mRadius); } catch (RSRuntimeException e) { bitmap = blur(bitmap, mRadius, true); } } else { bitmap = blur(bitmap, mRadius, true); } return BitmapResource.obtain(bitmap, mBitmapPool); }
Example #15
Source File: BlurTransformation.java From giffun with Apache License 2.0 | 5 votes |
@Override public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { Bitmap source = resource.get(); int width = source.getWidth(); int height = source.getHeight(); int scaledWidth = width / mSampling; int scaledHeight = height / mSampling; Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); if (bitmap == null) { bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) mSampling, 1 / (float) mSampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(source, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { bitmap = RSBlur.blur(mContext, bitmap, mRadius); } catch (RSRuntimeException e) { bitmap = FastBlur.blur(bitmap, mRadius, true); } } else { bitmap = FastBlur.blur(bitmap, mRadius, true); } return BitmapResource.obtain(bitmap, mBitmapPool); }
Example #16
Source File: BlurTransformation.java From Orin with GNU General Public License v3.0 | 4 votes |
@Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { int sampling; if (this.sampling == 0) { sampling = ImageUtil.calculateInSampleSize(toTransform.getWidth(), toTransform.getHeight(), 100); } else { sampling = this.sampling; } int width = toTransform.getWidth(); int height = toTransform.getHeight(); int scaledWidth = width / sampling; int scaledHeight = height / sampling; Bitmap out = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); if (out == null) { out = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(out); canvas.scale(1 / (float) sampling, 1 / (float) sampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(toTransform, 0, 0, paint); if (Build.VERSION.SDK_INT >= 17) { try { final RenderScript rs = RenderScript.create(context.getApplicationContext()); final Allocation input = Allocation.createFromBitmap(rs, out, 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(blurRadius); script.setInput(input); script.forEach(output); output.copyTo(out); rs.destroy(); return out; } catch (RSRuntimeException e) { // on some devices RenderScript.create() throws: android.support.v8.renderscript.RSRuntimeException: Error loading libRSSupport library if (BuildConfig.DEBUG) e.printStackTrace(); } } return StackBlur.blur(out, blurRadius); }
Example #17
Source File: BlurTransformation.java From RetroMusicPlayer with GNU General Public License v3.0 | 4 votes |
@Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { int sampling; if (this.sampling == 0) { sampling = ImageUtil.calculateInSampleSize(toTransform.getWidth(), toTransform.getHeight(), 100); } else { sampling = this.sampling; } int width = toTransform.getWidth(); int height = toTransform.getHeight(); int scaledWidth = width / sampling; int scaledHeight = height / sampling; Bitmap out = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); if (out == null) { out = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(out); canvas.scale(1 / (float) sampling, 1 / (float) sampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(toTransform, 0, 0, paint); if (Build.VERSION.SDK_INT >= 17) { try { final RenderScript rs = RenderScript.create(context.getApplicationContext()); final Allocation input = Allocation.createFromBitmap(rs, out, 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(blurRadius); script.setInput(input); script.forEach(output); output.copyTo(out); rs.destroy(); return out; } catch (RSRuntimeException e) { // on some devices RenderScript.create() throws: android.support.v8.renderscript.RSRuntimeException: Error loading libRSSupport library if (BuildConfig.DEBUG) e.printStackTrace(); } } return StackBlur.blur(out, blurRadius); }
Example #18
Source File: BlurTransformation.java From VinylMusicPlayer with GNU General Public License v3.0 | 4 votes |
@Override protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { int sampling; if (this.sampling == 0) { sampling = ImageUtil.calculateInSampleSize(toTransform.getWidth(), toTransform.getHeight(), 100); } else { sampling = this.sampling; } int width = toTransform.getWidth(); int height = toTransform.getHeight(); int scaledWidth = width / sampling; int scaledHeight = height / sampling; Bitmap out = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); if (out == null) { out = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(out); canvas.scale(1 / (float) sampling, 1 / (float) sampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(toTransform, 0, 0, paint); if (Build.VERSION.SDK_INT >= 17) { try { final RenderScript rs = RenderScript.create(context.getApplicationContext()); final Allocation input = Allocation.createFromBitmap(rs, out, 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(blurRadius); script.setInput(input); script.forEach(output); output.copyTo(out); rs.destroy(); return out; } catch (RSRuntimeException e) { // on some devices RenderScript.create() throws: android.support.v8.renderscript.RSRuntimeException: Error loading libRSSupport library if (BuildConfig.DEBUG) e.printStackTrace(); } } return StackBlur.blur(out, blurRadius); }
Example #19
Source File: BlurTransformation.java From MusicPlayer with GNU General Public License v3.0 | 4 votes |
@Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { int sampling; if (this.sampling == 0) { sampling = ImageUtil.calculateInSampleSize(toTransform.getWidth(), toTransform.getHeight(), 100); } else { sampling = this.sampling; } int width = toTransform.getWidth(); int height = toTransform.getHeight(); int scaledWidth = width / sampling; int scaledHeight = height / sampling; Bitmap out = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); if (out == null) { out = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(out); canvas.scale(1 / (float) sampling, 1 / (float) sampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(toTransform, 0, 0, paint); if (Build.VERSION.SDK_INT >= 17) { try { final RenderScript rs = RenderScript.create(context.getApplicationContext()); final Allocation input = Allocation.createFromBitmap(rs, out, 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(blurRadius); script.setInput(input); script.forEach(output); output.copyTo(out); rs.destroy(); return out; } catch (RSRuntimeException e) { // on some devices RenderScript.create() throws: android.support.v8.renderscript.RSRuntimeException: Error loading libRSSupport library if (BuildConfig.DEBUG) e.printStackTrace(); } } return StackBlur.blur(out, blurRadius); }
Example #20
Source File: BlurTransformation.java From Phonograph with GNU General Public License v3.0 | 4 votes |
@Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { int sampling; if (this.sampling == 0) { sampling = ImageUtil.calculateInSampleSize(toTransform.getWidth(), toTransform.getHeight(), 100); } else { sampling = this.sampling; } int width = toTransform.getWidth(); int height = toTransform.getHeight(); int scaledWidth = width / sampling; int scaledHeight = height / sampling; Bitmap out = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); if (out == null) { out = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(out); canvas.scale(1 / (float) sampling, 1 / (float) sampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(toTransform, 0, 0, paint); if (Build.VERSION.SDK_INT >= 17) { try { final RenderScript rs = RenderScript.create(context.getApplicationContext()); final Allocation input = Allocation.createFromBitmap(rs, out, 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(blurRadius); script.setInput(input); script.forEach(output); output.copyTo(out); rs.destroy(); return out; } catch (RSRuntimeException e) { // on some devices RenderScript.create() throws: android.support.v8.renderscript.RSRuntimeException: Error loading libRSSupport library if (BuildConfig.DEBUG) e.printStackTrace(); } } return StackBlur.blur(out, blurRadius); }
Example #21
Source File: BlurTransformation.java From Music-Player with GNU General Public License v3.0 | 4 votes |
@Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { int sampling; if (this.sampling == 0) { sampling = ImageUtil.calculateInSampleSize(toTransform.getWidth(), toTransform.getHeight(), 100); } else { sampling = this.sampling; } int width = toTransform.getWidth(); int height = toTransform.getHeight(); int scaledWidth = width / sampling; int scaledHeight = height / sampling; Bitmap out = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); if (out == null) { out = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(out); canvas.scale(1 / (float) sampling, 1 / (float) sampling); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(toTransform, 0, 0, paint); if (Build.VERSION.SDK_INT >= 17) { try { final RenderScript rs = RenderScript.create(context.getApplicationContext()); final Allocation input = Allocation.createFromBitmap(rs, out, 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(blurRadius); script.setInput(input); script.forEach(output); output.copyTo(out); rs.destroy(); return out; } catch (RSRuntimeException e) { // on some devices RenderScript.create() throws: android.support.v8.renderscript.RSRuntimeException: Error loading libRSSupport library if (BuildConfig.DEBUG) e.printStackTrace(); } } return StackBlur.blur(out, blurRadius); }