Java Code Examples for android.graphics.Paint.setFilterBitmap()

The following are Jave code examples for showing how to use setFilterBitmap() of the android.graphics.Paint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: aos-MediaLib   File: Utils.java   View Source Code Vote up 6 votes
public static void setBackground(View v, Bitmap bm) {

        if (bm == null) {
            v.setBackgroundResource(0);
            return;
        }

        int vwidth = v.getWidth()/4;
        int vheight = v.getHeight()/4;
        int bwidth = bm.getWidth();
        int bheight = bm.getHeight();
        float scalex = (float) vwidth / bwidth;
        float scaley = (float) vheight / bheight;
        float scale = Math.max(scalex, scaley) * 1.3f;

        Bitmap.Config config = Bitmap.Config.ARGB_8888;
        Bitmap bg = Bitmap.createBitmap(vwidth, vheight, config);
        Canvas c = new Canvas(bg);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);
        ColorMatrix greymatrix = new ColorMatrix();
        greymatrix.setSaturation(0);
        ColorMatrix darkmatrix = new ColorMatrix();
        darkmatrix.setScale(1f, 1f, 1f, .1f);
        greymatrix.postConcat(darkmatrix);
        ColorFilter filter = new ColorMatrixColorFilter(greymatrix);
        paint.setColorFilter(filter);
        Matrix matrix = new Matrix();
        matrix.setTranslate(-bwidth/2, -bheight/2); // move bitmap center to origin
        matrix.postRotate(10);
        matrix.postScale(scale, scale);
        matrix.postTranslate(vwidth/2, vheight/2);  // Move bitmap center to view center
        c.drawBitmap(bm, matrix, paint);
        v.setBackgroundDrawable(new BitmapDrawable(bg));
    }
 
Example 2
Project: Android-Bubble-Game   File: GameScene.java   View Source Code Vote up 6 votes
public void render(Canvas canvas) {
  Rect dest = new Rect(0, 0, getWidth(), getHeight());
  Paint paint = new Paint();
  paint.setFilterBitmap(true);
  if (canvas != null) {
    canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.background1), null, dest, paint);
  }
  if (goodBubble != null) {
    goodBubble.draw(canvas);
  }
  if (heart != null) {
    heart.draw(canvas);
  }
  if (poisonBubble != null) {
    poisonBubble.draw(canvas);
  }
}
 
Example 3
Project: decoy   File: BaseZoomableImageView.java   View Source Code Vote up 6 votes
@SuppressLint("NewApi")
protected void initBaseZoomableImageView( Context context) {
	mPaint = new Paint();
	mPaint.setDither(true);
	mPaint.setFilterBitmap(true);
	mPaint.setAntiAlias(true);
	if(context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
		landscape = true;
	}else {
		landscape = false;
	}
	// Setup the refresh runnable
	mRefresh = new Runnable() {
		@Override
		public void run() {
			postInvalidate();
		}
	};		
}
 
Example 4
Project: android-ripple-pulse-animation   File: RoundedImageView.java   View Source Code Vote up 6 votes
public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
    Bitmap sbmp;
    if(bmp.getWidth() != radius || bmp.getHeight() != radius)
        sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false);
    else
        sbmp = bmp;
    Bitmap output = Bitmap.createBitmap(sbmp.getWidth(),
            sbmp.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xffa19774;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(sbmp.getWidth() / 2 + 0.7f, sbmp.getHeight() / 2 + 0.7f,
            sbmp.getWidth() / 2+0.1f, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(sbmp, rect, rect, paint);

    return output;
}
 
Example 5
Project: SimpleUILauncher   File: BaseRecyclerViewFastScrollPopup.java   View Source Code Vote up 6 votes
public BaseRecyclerViewFastScrollPopup(BaseRecyclerView rv, Resources res) {
    mRes = res;
    mRv = rv;

    mBgOriginalSize = res.getDimensionPixelSize(R.dimen.container_fastscroll_popup_size);
    mBg = rv.getContext().getDrawable(R.drawable.container_fastscroll_popup_bg);
    mBg.setBounds(0, 0, mBgOriginalSize, mBgOriginalSize);

    mTextPaint = new Paint();
    mTextPaint.setColor(Color.WHITE);
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextSize(res.getDimensionPixelSize(R.dimen.container_fastscroll_popup_text_size));

    mShadowPaint = new Paint();
    mShadowPaint.setAntiAlias(true);
    mShadowPaint.setFilterBitmap(true);
    mShadowPaint.setDither(true);
}
 
Example 6
Project: Open-Quran-Radio   File: ImageHelper.java   View Source Code Vote up 6 votes
public Bitmap createCircularFramedImage(int size, int color) {

        Paint background = createBackground(color);

        // create empty bitmap and canvas
        Bitmap outputImage = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
        Canvas imageCanvas = new Canvas(outputImage);

        // draw circular background
        float cx = size / 2;
        float cy = size / 2;
        float radius = size / 2;
        imageCanvas.drawCircle(cx, cy, radius, background);

        // draw input image onto canvas using transformation matrix
        Paint paint = new Paint();
        paint.setFilterBitmap(true);
        imageCanvas.drawBitmap(mInputImage, createTransformationMatrix(size), paint);

        return outputImage;
    }
 
Example 7
Project: DereHelper   File: BeatMapView.java   View Source Code Vote up 5 votes
public BeatMapView(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    mBitPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBitPaint.setFilterBitmap(true);
    mBitPaint.setDither(true);

    note_0 = Utils.readBitMap(context, R.drawable.ic_note_0);
    note_1 = Utils.readBitMap(context, R.drawable.ic_note_1);
    note_2 = Utils.readBitMap(context, R.drawable.ic_note_2);
    note_3 = Utils.readBitMap(context, R.drawable.ic_note_3);
    note_4 = Utils.readBitMap(context, R.drawable.ic_note_4);

}
 
Example 8
Project: android-mvp-interactor-architecture   File: RoundedImageView.java   View Source Code Vote up 5 votes
private Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
    Bitmap finalBitmap;

    if (bitmap.getWidth() != radius || bitmap.getHeight() != radius) {
        finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false);
    } else {
        finalBitmap = bitmap;
    }

    Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
            finalBitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
            finalBitmap.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(finalBitmap.getWidth() / 2,
            finalBitmap.getHeight() / 2,
            finalBitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(finalBitmap, rect, rect, paint);

    return output;
}
 
Example 9
Project: CommonLibrary   File: RoundImageView.java   View Source Code Vote up 5 votes
/**
   * 边缘画圆
   */
  private void drawCircleBorder(Canvas canvas, int radius, int w, int h, int color) {
      Paint paint = new Paint();
      paint.setAntiAlias(true);
      paint.setFilterBitmap(true);
      paint.setDither(true);
      paint.setColor(color);
      /* 设置paint的 style 为STROKE:空心 */
      paint.setStyle(Paint.Style.STROKE);
/* 设置paint的外框宽度 */
      paint.setStrokeWidth(mBorderThickness);
      canvas.drawCircle(w / 2, h / 2, radius, paint);
  }
 
Example 10
Project: letv   File: RoundImageView.java   View Source Code Vote up 5 votes
public Bitmap getCroppedRoundBitmap(Bitmap bmp, int radius) {
    Bitmap squareBitmap;
    Bitmap scaledSrcBmp;
    int diameter = radius * 2;
    int bmpWidth = bmp.getWidth();
    int bmpHeight = bmp.getHeight();
    Bitmap bitmap;
    int i;
    if (bmpHeight > bmpWidth) {
        bitmap = bmp;
        i = (bmpHeight - bmpWidth) / 2;
        squareBitmap = Bitmap.createBitmap(bitmap, 0, i, bmpWidth, bmpWidth);
    } else if (bmpHeight < bmpWidth) {
        int x = (bmpWidth - bmpHeight) / 2;
        bitmap = bmp;
        i = 0;
        squareBitmap = Bitmap.createBitmap(bitmap, x, i, bmpHeight, bmpHeight);
    } else {
        squareBitmap = bmp;
    }
    if (squareBitmap.getWidth() == diameter && squareBitmap.getHeight() == diameter) {
        scaledSrcBmp = squareBitmap;
    } else {
        scaledSrcBmp = Bitmap.createScaledBitmap(squareBitmap, diameter, diameter, true);
    }
    Bitmap output = Bitmap.createBitmap(scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight());
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle((float) (scaledSrcBmp.getWidth() / 2), (float) (scaledSrcBmp.getHeight() / 2), (float) (scaledSrcBmp.getWidth() / 2), paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(scaledSrcBmp, rect, rect, paint);
    return output;
}
 
Example 11
Project: ImageMagnifier   File: MainActivity.java   View Source Code Vote up 5 votes
public Bitmap resizeBitmapByCanvas() {
    float width;
    float height;
    float originalWidth = (float) this.originalBitmap.getWidth();
    float originalHeight = (float) this.originalBitmap.getHeight();
    if (originalWidth > originalHeight) {
        width = (float) this.containerWidth;
        height = (((float) this.containerWidth) * originalHeight) / originalWidth;
    } else {
        height = (float) this.containerHeight;
        width = (((float) this.containerHeight) * originalWidth) / originalHeight;
    }
    if (width > originalWidth || height > originalHeight) {
        return this.originalBitmap;
    }
    Bitmap background = Bitmap.createBitmap((int) width, (int) height, Config.ARGB_8888);
    Canvas canvas = new Canvas(background);
    float scale = width / originalWidth;
    float yTranslation = (height - (originalHeight * scale)) / 2.0f;
    Matrix transformation = new Matrix();
    transformation.postTranslate(0.0f, yTranslation);
    transformation.preScale(scale, scale);
    Paint paint = new Paint();
    paint.setFilterBitmap(true);
    canvas.drawBitmap(this.originalBitmap, transformation, paint);
    return background;
}
 
Example 12
Project: PaoMovie   File: RangeSeekBar.java   View Source Code Vote up 5 votes
/**
 * 取得thumb值的paint
 */
private Paint getThumbValuePaint() {
	Paint p = new Paint();
	p.setColor(Color.RED);
	p.setAntiAlias(true);// 去除锯齿
	p.setFilterBitmap(true);// 对位图进行滤波处理
	p.setTextSize(35);

	return p;
}
 
Example 13
Project: 19porn   File: CircleImageView.java   View Source Code Vote up 5 votes
@Override
protected void onDraw(Canvas paramCanvas) {
    if (useDefaultStyle) {
        super.onDraw(paramCanvas);
        return;
    }
    final Drawable localDrawable = getDrawable();
    if (localDrawable == null)
        return;
    if (localDrawable instanceof NinePatchDrawable) {
        return;
    }
    if (this.paint == null) {
        final Paint localPaint = new Paint();
        localPaint.setFilterBitmap(false);
        localPaint.setAntiAlias(true);
        localPaint.setXfermode(MASK_XFERMODE);
        this.paint = localPaint;
    }
    final int width = getWidth();
    final int height = getHeight();
    /** 保存layer */
    int layer = paramCanvas.saveLayer(0.0F, 0.0F, width, height, null, 31);
    /** 设置drawable的大小 */
    localDrawable.setBounds(0, 0, width, height);
    /** 将drawable绑定到bitmap(this.mask)上面(drawable只能通过bitmap显示出来) */
    localDrawable.draw(paramCanvas);
    if ((this.mask == null) || (this.mask.isRecycled())) {
        this.mask = createOvalBitmap(width, height);
    }
    /** 将bitmap画到canvas上面 */
    paramCanvas.drawBitmap(this.mask, 0.0F, 0.0F, this.paint);
    /** 将画布复制到layer上 */
    paramCanvas.restoreToCount(layer);
    drawBorder(paramCanvas, width, height);
}
 
Example 14
Project: CSipSimple   File: PointCloud.java   View Source Code Vote up 5 votes
public PointCloud(Drawable drawable) {
    mPaint = new Paint();
    mPaint.setFilterBitmap(true);
    mPaint.setColor(Color.rgb(255, 255, 255)); // TODO: make configurable
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);

    mDrawable = drawable;
    if (mDrawable != null) {
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    }
}
 
Example 15
Project: eggs-android   File: RoundedImageView.java   View Source Code Vote up 5 votes
private Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
    Bitmap finalBitmap;

    if (bitmap.getWidth() != radius || bitmap.getHeight() != radius) {
        finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false);
    } else {
        finalBitmap = bitmap;
    }

    Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
            finalBitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
            finalBitmap.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(finalBitmap.getWidth() / 2,
            finalBitmap.getHeight() / 2,
            finalBitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(finalBitmap, rect, rect, paint);

    return output;
}
 
Example 16
Project: android-mvp-architecture   File: RoundedImageView.java   View Source Code Vote up 5 votes
private Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
    Bitmap finalBitmap;

    if (bitmap.getWidth() != radius || bitmap.getHeight() != radius) {
        finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false);
    } else {
        finalBitmap = bitmap;
    }

    Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
            finalBitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
            finalBitmap.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(finalBitmap.getWidth() / 2,
            finalBitmap.getHeight() / 2,
            finalBitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(finalBitmap, rect, rect, paint);

    return output;
}
 
Example 17
Project: RLibrary   File: FingerPrinterView.java   View Source Code Vote up 5 votes
private void initPaint() {
    mBitPaint = new Paint();
    // 防抖动
    mBitPaint.setDither(true);
    // 开启图像过滤
    mBitPaint.setFilterBitmap(true);
}
 
Example 18
Project: ForeverLibrary   File: FastBitmapDrawable.java   View Source Code Vote up 5 votes
public FastBitmapDrawable(Bitmap b) {
    mBitmap = b;
    if (null != mBitmap) {
        mIntrinsicWidth = mBitmap.getWidth();
        mIntrinsicHeight = mBitmap.getHeight();
    } else {
        mIntrinsicWidth = 0;
        mIntrinsicHeight = 0;
    }
    mPaint = new Paint();
    mPaint.setDither(true);
    mPaint.setFilterBitmap(true);
}
 
Example 19
Project: GifImageLoader   File: RoundedBitmapDisplayer.java   View Source Code Vote up 5 votes
public RoundedDrawable(Bitmap bitmap, int cornerRadius, int margin) {
    this.cornerRadius = cornerRadius;
    this.margin = margin;

    bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    mBitmapRect = new RectF(margin, margin, bitmap.getWidth() - margin, bitmap.getHeight() - margin);

    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(bitmapShader);
    paint.setFilterBitmap(true);
    paint.setDither(true);
}
 
Example 20
Project: MarsBootProject   File: RoundImageView.java   View Source Code Vote up 4 votes
/**
 * 获取裁剪后的圆形图片
 *
 * @param radius 半径
 * @param bmp    要被裁减的图片
 */
public Bitmap getCroppedRoundBitmap(Bitmap bmp, int radius) {
    Bitmap scaledSrcBmp;
    int diameter = radius * 2;
    // 为了防止宽高不相等,造成圆形图片变形,因此截取长方形中处于中间位置最大的正方形图片
    int bmpWidth = bmp.getWidth();
    int bmpHeight = bmp.getHeight();
    int squareWidth = 0, squareHeight = 0;
    int x = 0, y = 0;
    Bitmap squareBitmap;
    if (bmpHeight > bmpWidth) {// 高大于宽
        squareWidth = squareHeight = bmpWidth;
        x = 0;
        y = (bmpHeight - bmpWidth) / 2;
        // 截取正方形图片
        squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth, squareHeight);
    } else if (bmpHeight < bmpWidth) {// 宽大于高
        squareWidth = squareHeight = bmpHeight;
        x = (bmpWidth - bmpHeight) / 2;
        y = 0;
        squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth, squareHeight);
    } else {
        squareBitmap = bmp;
    }

    if (squareBitmap.getWidth() != diameter || squareBitmap.getHeight() != diameter) {
        scaledSrcBmp = Bitmap.createScaledBitmap(squareBitmap, diameter, diameter, true);

    } else {
        scaledSrcBmp = squareBitmap;
    }
    Bitmap output = Bitmap.createBitmap(scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(scaledSrcBmp.getWidth() / 2, scaledSrcBmp.getHeight() / 2, scaledSrcBmp.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(scaledSrcBmp, rect, rect, paint);
    // 回收资源
    // bmp.recycle();
    // squareBitmap.recycle();
    // scaledSrcBmp.recycle();
    bmp = null;
    squareBitmap = null;
    scaledSrcBmp = null;
    return output;
}