Modify onDraw() method of MyView.java in last exercise.
@Override
protected void onDraw(Canvas canvas) {
//To generate negative image
float[] colorMatrix_Negative = {
-1.0f, 0, 0, 0, 255, //red
0, -1.0f, 0, 0, 255, //green
0, 0, -1.0f, 0, 255, //blue
0, 0, 0, 1.0f, 0 //alpha
};
Paint MyPaint_Normal = new Paint();
Paint MyPaint_Negative = new Paint();
ColorFilter colorFilter_Negative = new ColorMatrixColorFilter(colorMatrix_Negative);
MyPaint_Negative.setColorFilter(colorFilter_Negative);
Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
canvas.drawBitmap(myBitmap, 400, 100, MyPaint_Normal);
canvas.drawBitmap(myBitmap, 500, 100, MyPaint_Negative);
};
![download files download files](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8p8OYSJ34x9VZ9cj4IzAOVtRlBOzcLrPRJWQ4iuiJI1eCKjrLYOEL2p2RYTNBidfvJuDOpoiZjXICYCF5ifVUBp09IMGbHsHFSOko1_Xdf4gYrG9MbcBSZDywv5SWAQhCav5OT9OGPE5T/s200/icons_download.gif)
No comments:
Post a Comment