Python拼图,python图像处理拼图

  Python拼图,python图像处理拼图

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

  创建函数:

  protectedvoidoncreate(bundlesavedinstancestate)super。oncreate)savedinstancestate;设置内容视图(r .布局活动_主要;imageview=(imageview)findviewbyid)r . idimageview位图背景=位图工厂。解码资源(获取资源),r . drawable。背);位图前景=位图工厂。解码资源(获取资源),r . drawable。平面);/* canvas画布=新画布(背景);drawimage(canvas,background,0,foreground.getHeight)、前景。获取width/2 */bid imageview。setimage位图;)连接函数:

  方法1 :

  span style= font-size:18px;privatebitmaptoconformambitmap(位图背景,位图前景)if)background==null {返回null;} intbgwidth=背景。getwidth(;intb gheight=背景。获取高度(;int fg width=前景。getwidth(;intf gheight=前景。获取高度(;重新创建与//src的长度相同宽度的位图bitmapnewbmp=位图。创建位图(bgwidthfgwidth,bgHeight fgHeight,Config .ARGB _ 8888)cv . draw位图(背景,0,0,null);开始在//0,0坐标上绘制BGcv.drawbitmap(前景,0,bgHeight,null);保存简历。还原(可在//0,0坐标处开始绘制细粒并从任意位置绘制简历。保存(画布。all _ save _ flag));//存储返回新的wbmp(}/span

  方法2 :

  span style= font-size:18px;专用位图(bitmaptoconformbitmap,位图背景)if)background==null)span style= white-spack ground(位图)intb gheight=背景。获取高度(;int fg width=前景。getwidth(;intf gheight=前景。获取高度(;重新创建与//src的长度相同宽度的位图bitmapnewbmp=位图。创建位图(bgwidthfgwidth,bgHeight fgHeight,Config .ARGB_8888 ) //方法Rect dst=new Rect(;夏令时。左=0;夏令时。top=0;dst.right=bgWidthdst。bottom=bgHeight-50;cv.drawbitmap(background,null,dst,null);Rect dst 2=new Rect(;夏令时2。左=0;夏令时2。top=bgHeightdouble Xscale=BG宽度/fg宽度;//X轴缩放dst2 .bottom=(int))bgHeight fgHeight * Xscale;夏令时2。右=背景宽度;cv.drawbitmap(前景,null,dst2,null);dst2=空;dst=nullcv。保存(画布。all _ save _ flag);保存简历。restore();//存储返回新的wbmp(}/span保存函数:

  将位图另存为一张图像privatestringsavebitmap(位图位图){ string image path=get application).获取文件目录。获取绝对过滤器if(文件。exists()){ file。删除;} try { file output stream out=新文件输出流(file);位图.压缩出版社(bitmap.compress format.png,100,out)){ out。同花顺;出去。关闭(;}文件保护(filenotfoundexceptione )/todo自动生成catchblocke.print堆栈跟踪);}catch(ioexceptione )/todo自动生成catchblocktoast.maketext (this,保存失败,1 ).秀);e .打印任务跟踪(;}返回图像路径}

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: