android:camera中HAL层在UI中划线
android camera的HAL层中是一些和硬件相关的中间处理,这里是无法得到UI的,因为无法直接控制画面,如果想在camera预览画面上显示一些信息,可以通过改变camera每一帧的实际数据来得到相应的效果。
下面是在HAL层camera中划线的一段代码。输入参数包括了当前帧数据的luma分量和chroma分量,还有就是划线起始点和终止点的坐标xy数值。
//paint void paintLine(unsigned char *luma, unsigned char *chroma, int xx1, int yy1, int xx2, int yy2) { // check pixel if (xx1 == xx2 && yy1 == yy2) { paintPixel(luma, chroma, xx1, yy1); return; } // paint line double x1 = xx1; double y1 = yy1; double x2 = xx2; double y2 = yy2; if (abs(x2 - x1) >= abs(y2 - y1)) { double pitch = (y2 - y1) / (x2 - x1); if (x2 >= x1) { for (double i = x1; i <= x2; i++) { paintPixel(luma, chroma, (int)i, (int)((i-x1) * pitch + y1)); } } else { for (double i = x2; i <= x1; i++) { paintPixel(luma, chroma, (int)i, (int)((i - x2) * pitch + y2)); } } } else { double pitch = (x2 - x1) / (y2 - y1); if (y2 >= y1) { for (double i = y1; i <= y2; i++) { paintPixel(luma, chroma, (int)((i - y1) * pitch + x1), (int)i); } } else { for (double i = y2; i <= y1; i++) { paintPixel(luma, chroma, (int)((i - y2) * pitch + x2), (int)i); } } } }
void paintPixel(unsigned char *luma, unsigned char *chroma, int x, int y) { luma[y * nPicWidth + x] = 255; chroma[y / 2 * nPicWidth + x] = 128; chroma[y / 2 * nPicWidth + x + 1] = 128; }
当然通过自定义一些数学模型,也可以在画面中描画出一些其他形状的图形了。
PS:上面的代码会在(xx1, yy1)点和(xx2, yy2)点之间划出一条红色线段。
红色的控制在paintPixel方法中控制。