- Linux 下使用 QT 调用 opencv 读取摄像头视频 调试心得
- Android 开发 摄像头 SurfaceView 预览 背景带矩形框 实现
- Android 开发:安装 NDK,移植 OpenCV2.3.1,JNI 调用 OpenCV 全过程
- try to load OpenCV.mk from default install location
- Android 摄像头开发完美 demo
- 如何设置 ImageButton 按键按下去后的 特效
- Android 摄像头:只拍摄 SurfaceView 预览界面特定区域内容(矩形框)
- Android 开发:SurfaceView 上新建线程绘制旋转图片 及 刷新特定区域(脏矩形)
- Android 开发:ImageView 上绘制旋转圆环(透明度不同的旋转圆环,利用 canvas.drawArc 实现)
- Android 上掌纹识别第一步:基于 OpenCV 的 6 种肤色分割 源码和效果图
- Android 开发:实时处理摄像头预览帧视频 - 浅析
- Android 摄像头开发:拍照后添加相框,融合相框和图片为一副 图片
- Android(OpenCV) NDK 开发: 0xdeadbaad(code=1) 错误 及 关闭 armeabi 和 libnative_camera_r2.2.2.so 的生成
- Android 摄像头开发:实时摄像头视频预览帧的编码问题(二)
- setContentView 切换页面(无需每次都 findViewById) - 二
- Android 开发:setContentView 切换界面,自定义带 CheckBox 的 ListView 显示 SQlite 条目 - 实现
Android 摄像头开发:拍照后添加相框,融合相框和图片为一副 图片
为了添加相框,可以新建一个 bitmap,依此实例化一个 canvas。然后再上面依次画上原图和相框。
在 onPictureTaken()函数里,得到原始 bitmap 后,得到相框,然后调用融合函数。
Bitmap frame = BitmapFactory.decodeResource(getResources(), R.drawable.border);
Bitmap monBM = montageBitmap(frame, sizeBitmap, 200, 200);
/*将像框和图片进行融合,返回一个 Bitmap*/
public Bitmap montageBitmap(Bitmap frame, Bitmap src, int x, int y){
int w = src.getWidth();
int h = src.getHeight();
Bitmap sizeFrame = Bitmap.createScaledBitmap(frame, w, h, true);
Bitmap newBM = Bitmap.createBitmap(w, h, Config.ARGB_8888);
Canvas canvas = new Canvas(newBM);
canvas.drawBitmap(src, x, y, null);
canvas.drawBitmap(sizeFrame, 0, 0, null);
return newBM;
}
程序中 frame 代表相框,src 代表原图,大小为 600800.首先将相框的大小缩放到 600800,然后实例化一个 canvas。记住先画原图。这里面有个 x、y 坐标。
这里是这个 api 的注释:
public void drawBitmap (Bitmap bitmap, float left, float top, Paint paint)
Added in API level 1
Draw the specified bitmap, with its top/left corner at (x,y), using the specified
paint, transformed by the current matrix.
Note: if the paint contains a maskfilter that generates a mask which extends beyond the bitmap's
original width/height (e.g. BlurMaskFilter), then the bitmap will be drawn as if it were in a Shader
with CLAMP mode. Thus the color outside of the original width/height will be the edge color replicated.
If the bitmap and canvas have different densities, this function will take care of
automatically scaling the bitmap to draw at the same density as the canvas.
Parameters
bitmap The bitmap to be drawn
left The position of the left side of the bitmap being drawn
top The position of the top side of the bitmap being drawn
paint The paint used to draw the bitmap (may be null)
看上面的解释,貌似不清楚这个 x y 坐标到底是谁的坐标,是原图的 还是 canvas 的?而且如果要画的图超过 canvas 的大小怎么办?经过实际测试,参考 这里 ,这个 x、y 坐标是指 canvas 上的,也就是以 canvas 上的点(x,y)为顶点,来画图 bitmap。如果 bitmap 的大小超过 canvas 的大小,就不显示了。下面两组测试图片可以清楚看到。
第一组测试照片(x,y)=(20, 20):
原图:
原图+相框:
第二组(x,y)=(200, 200):
原图:
原图+相框:
可以看到,当传进去的坐标较小时看不出来啥差别。事实上,如果将两个坐标都设为(0,0),看到的是两个同样大小的照片层叠的效果。这就看对相框如何定义了。如果要求不遮挡原图,则需要把原图缩放到 rect 大小,这个 rect 是指相框里面的空白(透明)部分大小。然后从 canvas 的透明部分的左上顶点开始画缩放后的原图。
http://blog.csdn.net/lgl125/article/details/7866930 这个链接是给原图加边框的,但不是相框!可以参考。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论