问题描述
使用V4L2进行视频采集,采集到的视频数据分辨率为320x240(4:3),使用Canvas,drawBitmap方式在Android设备上预览图像
Android设备分辨率为 540x960(9:16),所以全屏预览时图像被拉伸,这种问题如何解决?
没思路啊,哪位大神指导指导!!
下面是画图像的代码,大神们帮忙看看
public void run() { //获取屏幕信息 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int screenWidth = dm.widthPixels; int screenHeigh = dm.heightPixels; Log.i(tag, "------------进入DrawImage---------------"); Log.i(tag, "当前屏幕宽为:" + screenWidth + ", 当前屏幕高为: " + screenHeigh); Log.i(tag, "进入DrawImage USB摄像头当前状态为" + cameraExists); while (cameraExists) { // rect = new Rect(0, 0, screenWidth/2, screenHeigh/2); rectF = new RectF(0, 0, screenWidth, screenHeigh); //w和h分别是屏幕的宽和高,也就是你想让图片显示的宽和高 // Log.i(tag, "------------USB摄像头开始画图---------------"); if (bmp != null) { Canvas canvas = holder.lockCanvas(); if (canvas != null) { // canvas.drawBitmap(bmp, null, rect, null); canvas.drawBitmap(bmp, null, rectF, null); holder.unlockCanvasAndPost(canvas); } } } Log.i(tag, "线程退出DrawImage"); }
解决方案1
canvas.drawBitmap(srcBitmap, matrix, null); 用矩阵缩放一下试试。
时间: 2024-12-29 11:14:15