public class MainActivity extends Activity {
private ImageView iv_1;
private ImageView iv_2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv_1 = (ImageView) findViewById(R.id.iv_1);
iv_2 = (ImageView) findViewById(R.id.iv_2);
//导入图片资源,该图片是只读的
Bitmap map = BitmapFactory.decodeResource(getResources(),
R.drawable.gif);
iv_1.setImageBitmap(map);
//创建一个可修改的
Bitmap altermap = Bitmap.createBitmap(map.getWidth(),
map.getHeight(), map.getConfig());
//创建画布,绑定可修改的图版
Canvas canvas = new Canvas(altermap);
//对图片操作的矩阵
Matrix matrix = new Matrix();
//画笔
Paint paint = new Paint();
//图片的合成
//paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.MULTIPLY));
paint.setColor(Color.BLACK);
// 图片的缩放
// matrix.setScale(2.0f, 1);
// 图片的旋转
// matrix.setRotate(180, map.getWidth()/2, map.getHeight()/2);
//图片的平移
//matrix.setTranslate(10, 10);
//镜面效果
// matrix.setScale(-1, 1);
// matrix.postTranslate(map.getWidth(), 0);
//倒影效果
matrix.setScale(1, -1);
matrix.postTranslate(0, map.getHeight());
canvas.drawBitmap(map, matrix, paint);
iv_2.setImageBitmap(altermap);
}
}
private ImageView iv_1;
private ImageView iv_2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv_1 = (ImageView) findViewById(R.id.iv_1);
iv_2 = (ImageView) findViewById(R.id.iv_2);
//导入图片资源,该图片是只读的
Bitmap map = BitmapFactory.decodeResource(getResources(),
R.drawable.gif);
iv_1.setImageBitmap(map);
//创建一个可修改的
Bitmap altermap = Bitmap.createBitmap(map.getWidth(),
map.getHeight(), map.getConfig());
//创建画布,绑定可修改的图版
Canvas canvas = new Canvas(altermap);
//对图片操作的矩阵
Matrix matrix = new Matrix();
//画笔
Paint paint = new Paint();
//图片的合成
//paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.MULTIPLY));
paint.setColor(Color.BLACK);
// 图片的缩放
// matrix.setScale(2.0f, 1);
// 图片的旋转
// matrix.setRotate(180, map.getWidth()/2, map.getHeight()/2);
//图片的平移
//matrix.setTranslate(10, 10);
//镜面效果
// matrix.setScale(-1, 1);
// matrix.postTranslate(map.getWidth(), 0);
//倒影效果
matrix.setScale(1, -1);
matrix.postTranslate(0, map.getHeight());
canvas.drawBitmap(map, matrix, paint);
iv_2.setImageBitmap(altermap);
}
}