Android摄像头开发:拍照后添加相框,融合相框和图片为一副 图片
2013-02-28 15:37
453 查看
为了添加相框,可以新建一个bitmap,依此实例化一个canvas。然后再上面依次画上原图和相框。
在onPictureTaken()函数里,得到原始bitmap后,得到相框,然后调用融合函数。
Bitmap frame = BitmapFactory.decodeResource(getResources(), R.drawable.border);
Bitmap monBM = montageBitmap(frame, sizeBitmap, 200, 200);
#mailContentContainer .txt {height:auto;}
这里是这个api的注释:
第一组测试照片(x,y)=(20, 20):
原图:
原图+相框:
第二组(x,y)=(200, 200):
原图:
原图+相框:
可以看到,当传进去的坐标较小时看不出来啥差别。事实上,如果将两个坐标都设为(0,0),看到的是两个同样大小的照片层叠的效果。这就看对相框如何定义了。如果要求不遮挡原图,则需要把原图缩放到rect大小,这个rect是指相框里面的空白(透明)部分大小。然后从canvas的透明部分的左上顶点开始画缩放后的原图。
http://blog.csdn.net/lgl125/article/details/7866930这个链接是给原图加边框的,但不是相框!可以参考。
-----------------------------------------------------------------本文系原创,转载请注明作者:yanzi1225627
在onPictureTaken()函数里,得到原始bitmap后,得到相框,然后调用融合函数。
Bitmap frame = BitmapFactory.decodeResource(getResources(), R.drawable.border);
Bitmap monBM = montageBitmap(frame, sizeBitmap, 200, 200);
#mailContentContainer .txt {height:auto;}
/*将像框和图片进行融合,返回一个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代表原图,大小为600*800.首先将相框的大小缩放到600*800,然后实例化一个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这个链接是给原图加边框的,但不是相框!可以参考。
-----------------------------------------------------------------本文系原创,转载请注明作者:yanzi1225627
相关文章推荐
- 【android开发笔记】为Button的背景图片添加边框式样式效果
- 在Android 中调用选择图片、视频、添加音频、录音、拍摄视频、拍照等其他的功能
- 在Android 中调用选择图片、视频、添加音频、录音、拍摄视频、拍照等其他的功能
- Android开发之获取相册照片和获取拍照照片三之 图片旋转
- Android开发之调用摄像头拍照
- Android开发:仿微信和QQ空间发说说相册读取、拍照、图片裁剪和图片上传服务器等功能的实现
- Android开发手记(32) 使用摄像头拍照
- android 手机拍照上传项目的开发-----Camera1.2(图片文件的翻转及缩放操作)
- Android从相册选择图片和调用系统摄像头拍照
- IOS开发 两、三个界面相互传值,类似android的onActivityResult(拍照上传、预览图片、点击查看、删除)
- Android 图片合成:添加蒙板效果 不规则相框 透明度渐变效果的实现
- Android 实例讲解添加本地图片和调用系统拍照图片
- Android调用摄像头拍照开发教程
- android开发EditText中添加图片
- Android开发:Camera初探——控制摄像头拍照
- Android 图片合成:添加蒙板效果 不规则相框 透明度渐变效果的实现
- Android画板开发(四) 添加背景和保存画板内容为图片
- Android开发,调用相册图片或者调用相机进行拍照获取图片
- Android开发:相册读取、拍照、图片裁剪和图片上传服务器等功能的实现
- Android 图片合成:添加蒙板效果 不规则相框 透明度渐变效果的实现