首页 > 编程知识 正文

python图片拼接,图片拼接模板

时间:2023-05-05 06:12:47 阅读:133992 作者:1801

拼图代码——张图像拼接:

onCreate函数:

protectedvoidoncreate (bundlesavedinstancestate ) super.oncreate ) savedinstancestate; setcontentview (r.layout.activity _ main; imageview=(imageview ) findviewbyid ) r.id.imageview; bitmap background=bitmap factory.decode resource (get resources ),R.drawable.back ); bitmap foreground=bitmap factory.decode resource (get resources ),R.drawable.plane );/* canvas canvas=new canvas (background ); drawimage(canvas,background,0,foreground.getHeight )、foreground.getWidth )、background.getheight/2 */bid imageview.setimagebitmap; )连接函数:

方法1 :

span style='font-size:18px;' privatebitmaptoconformbitmap (bitmap background,Bitmap foreground ) if ) background==null { return null; } intbgwidth=background.getwidth (; intb gheight=background.getheight (; int fgWidth=foreground.getWidth (; intf gheight=foreground.getheight (; 重新创建与//src的长度相同宽度的位图bitmapnewbmp=bitmap.create bitmap (bgwidthfgwidth,bgHeight fgHeight,Config.ARGB_8888 ) cv.drawbitmap(background,0,0,null ); 开始在//0,0坐标上绘制BGcv.drawbitmap(foreground,0,bgHeight,null ); 保存cv.restore (可在//0,0坐标处开始绘制fg并从任意位置绘制cv.save(canvas.all_save_flag ) ); //存储返回新的wbmp; (}/span

方法2 :

span style='font-size:18px;' 专用位图(bitmaptoconformbitmap,bitmap background ) if ) background==null ) spanstyle='white-spackground (位图) intb gheight=background.getheight (; int fgWidth=foreground.getWidth (; intf gheight=foreground.getheight (; 重新创建与//src的长度相同宽度的位图bitmapnewbmp=bitmap.create bitmap (bgwidthfgwidth,bgHeight fgHeight,Config.ARGB_8888 ) //方法Rect dst=new Rect (; dst.left=0; dst.top=0; dst.right=bgWidth; dst.bottom=bgHeight-50; cv.drawbitmap(background,null,dst,null ); Rect dst2=new Rect (; dst2.left=0; dst2.top=bgHeight; double Xscale=bgWidth/fgWidth; //X轴缩放dst2.Bottom=(int ) ) bgHeight fgHeight*Xscale; dst2.right=bgWidth; cv.drawbitmap(foreground,null,dst2,null ); dst2=空; dst=null; cv.save(canvas.all_save_flag ); 保存cv.restore (); //存储返回新的wbmp; (}/span保存函数:

将bitmap另存为一张图像privatestringsavebitmap (bitmap bitmap ) { string image path=get application ).getfiles dir.get absoluter filuter if(file.exists () ) { file.delete; } try { fileoutputstreamout=new file output stream (file ); bitmap.com press (bitmap.compress format.png,100,out ) ) {out.flush; out.close (; }文件保护(filenotfoundexceptione )/todo auto-generatedcatchblocke.print stack trace ); }catch(ioexceptione )/todo auto-generatedcatchblocktoast.maketext (this,'保存失败',1 ).show ); e .打印任务跟踪(; } return imagePath; }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。