private void drawBitmap(Bitmap bitmap) {
Bitmap newBmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
Canvas canvas = new Canvas(newBmp);
Paint p = new Paint();
canvas.drawBitmap(bitmap, 0, 0, p);
imageView.setImageBitmap(newBmp);
}
private void drawMatrixBitmap(Bitmap bitmap) {
Bitmap newBmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
Canvas canvas = new Canvas(newBmp);
Paint p = new Paint();
// Matrix matrix = new Matrix();
// matrix.setValues(new float[]{
// .5f, 0, 0,
// 0, 1, 0,
// 0, 0, 1
// });
// Matrix matrix = new Matrix();
// matrix.setValues(new float[] {
// 1, .5f, 0,
// 0, 1, 0,
// 0, 0, 1
// });
Matrix matrix = new Matrix();
// matrix.setRotate(15);
// matrix.setScale(1,0.5f);
// matrix.setTranslate(1.5f,-10);
// matrix.setScale(1.5f, 1);
// matrix.postRotate(15,bitmap.getWidth()/2,bitmap.getHeight()/2);
// 镜像
// matrix.setScale(-1, 1);
// matrix.postTranslate(bitmap.getWidth(),0);
// 倒置
matrix.setScale(1, -1);
matrix.postTranslate(0, bitmap.getHeight());
canvas.drawBitmap(bitmap, matrix, p);
imageView.setImageBitmap(newBmp);
}
private void matrixAndBitmap(Bitmap bitmap) {
Matrix matrix = new Matrix();
matrix.setRotate(15, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
Bitmap alteredBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),
matrix, false);
imageView.setImageBitmap(alteredBitmap);
}
private void colorMatrixDraw(Bitmap bitmap) {
Bitmap alteredBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
Canvas canvas = new Canvas(alteredBitmap);
Paint paint = new Paint();
ColorMatrix cm = new ColorMatrix();
// cm.set(new float[] {
// 2, 0, 0, 0, 0,
// 0, 1, 0, 0, 0,
// 0, 0, 1, 0, 0,
// 0, 0, 0, 1, 0
// });
// float contrast = 2;
// cm.set(new float[] {
// contrast, 0, 0, 0, 0,
// 0, contrast, 0, 0, 0,
// 0, 0, contrast, 0, 0,
// 0, 0, 0, 1, 0 });
// float brightness = -25;
// cm.set(new float[] {
// 1, 0, 0, 0, brightness,
// 0, 1, 0, 0, brightness,
// 0, 0, 1, 0, brightness,
// 0, 0, 0, 1, 0 });
// float contrast = 2;
// float brightness = -25;
// cm.set(new float[] {
// contrast, 0, 0, 0, brightness,
// 0, contrast, 0, 0, brightness,
// 0, 0, contrast, 0, brightness,
// 0, 0, 0, contrast, 0 });
cm.setSaturation(0.5f);
paint.setColorFilter(new ColorMatrixColorFilter(cm));
Matrix matrix = new Matrix();
canvas.drawBitmap(bitmap, matrix, paint);
imageView.setImageBitmap(alteredBitmap);
}