Breaking News
Loading...
Tuesday 18 September 2012

Example of using PorterDuffColorFilter

23:29
android.graphics.PorterDuffColorFilter create a colorfilter that uses the specified color and porter-duff mode. The source color and porter-duff mode can be specified in the constructor, PorterDuffColorFilter (int srcColor, PorterDuff.Mode mode).

Example of using PorterDuffColorFilter


Modify onDraw() method of MyView.java in the post "Example of using ColorMatrixColorFilter".

 @Override
protected void onDraw(Canvas canvas) {

int srcColor= 0xFF00FF00;
PorterDuff.Mode mode = PorterDuff.Mode.ADD;

PorterDuffColorFilter porterDuffColorFilter
= new PorterDuffColorFilter(srcColor, mode);

Paint MyPaint_Normal = new Paint();
Paint MyPaint_PorterDuff = new Paint();
MyPaint_PorterDuff.setColorFilter(porterDuffColorFilter);

Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
canvas.drawBitmap(myBitmap, 400, 100, MyPaint_Normal);
canvas.drawBitmap(myBitmap, 500, 100, MyPaint_PorterDuff);

};


download filesDownload the files.

Related:
- Interactive demonstration of PorterDuffColorFilter.


0 comments:

Post a Comment

 
Toggle Footer