How to mirror an image file? (2.2+)

廉价感情. 提交于 2019-11-28 12:07:29

Scaling by -1.0 causes the image to be flipped. Assuming bmp is the bitmap you want to mirror (here on the x axis) you can do :

Matrix matrix = new Matrix(); 
matrix.preScale(-1.0f, 1.0f); 
Bitmap mirroredBitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.width(), bmp.height(), matrix, false);

If you don't want to create a second bitmap, you can do the same with canvas.scale :

canvas.save();
canvas.scale(-1.0f, 1.0f);
canvas.drawBitmap(bitmap, ...); // The bitmap is flipped
canvas.restore();

You can simply use View.setScaleX()

For example

 public void mirrorView(View v){
    v.setScaleX(-1.0f);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!