Java源码示例:jp.wasabeef.fresco.processors.internal.RSBlur

示例1
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;
}
 
示例2
@Override public void process(Bitmap dest, Bitmap source) {

    int width = source.getWidth();
    int height = source.getHeight();
    int scaledWidth = width / sampling;
    int scaledHeight = height / sampling;

    Bitmap blurredBitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(blurredBitmap);
    canvas.scale(1 / (float) sampling, 1 / (float) sampling);
    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 {
        blurredBitmap = RSBlur.blur(context, blurredBitmap, radius);
      } catch (android.renderscript.RSRuntimeException e) {
        blurredBitmap = FastBlur.blur(blurredBitmap, radius, true);
      }
    } else {
      blurredBitmap = FastBlur.blur(blurredBitmap, radius, true);
    }

    Bitmap scaledBitmap =
        Bitmap.createScaledBitmap(blurredBitmap, dest.getWidth(), dest.getHeight(), true);
    blurredBitmap.recycle();

    super.process(dest, scaledBitmap);
  }
 
示例3
@Override public void process(Bitmap dest, Bitmap source) {

    int width = source.getWidth();
    int height = source.getHeight();
    int scaledWidth = width / sampling;
    int scaledHeight = height / sampling;

    Bitmap blurredBitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(blurredBitmap);
    canvas.scale(1 / (float) sampling, 1 / (float) sampling);
    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 {
        blurredBitmap = RSBlur.blur(context, blurredBitmap, radius);
      } catch (android.renderscript.RSRuntimeException e) {
        blurredBitmap = FastBlur.blur(blurredBitmap, radius, true);
      }
    } else {
      blurredBitmap = FastBlur.blur(blurredBitmap, radius, true);
    }

    Bitmap scaledBitmap =
        Bitmap.createScaledBitmap(blurredBitmap, dest.getWidth(), dest.getHeight(), true);
    blurredBitmap.recycle();

    super.process(dest, scaledBitmap);
  }