画面倒置的实现(通过Bitmap图像旋转)

来源:互联网 发布:人工智能是什么意思 编辑:程序博客网 时间:2024/05/17 01:16

在项目中要实现一个播放画面的倒置,播放画面是通过解码后用Bitmap展示的,所以我通过图像旋转180°来实现。

在项目中定义一个Flag,来判定是否需要倒置。通过rotateBitmap()函数还可以实现任意角度的旋转。

//在播放画面View控件的OnDraw()方法中,加入下面的语句,通过isInvert判断是否倒置//其中VideoBitmap存放的是解码得到的画面信息if (isInvert == true) {VideoBitmap = rotateBitmap(VideoBitmap, 180);}//后面是对图片进行处理展示的代码,省略...//实现函数:public Bitmap rotateBitmap(Bitmap bitmap, int degrees) {if (degrees != 0 && bitmap != null) {Matrix matrix = new Matrix();matrix.setRotate(degrees, (float) bitmap.getWidth()/2,(float) bitmap.getHeight()/2);try {Bitmap tempBm = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),bitmap.getHeight(), matrix, true);if (bitmap != tempBm) {// bitmap回收bitmap.recycle();bitmap = tempBm;}} catch (Exception e) {// TODO 自动生成的 catch 块e.printStackTrace();}}return bitmap;}