Andriod arcgis保存Mapview为图片的实例代码
程序员文章站
2024-02-24 15:52:52
废话不多说了,直接给大家贴代码了,具体代码如下所述:
/**
* 把一个view的对象转换成bitmap
*/
private bitmap getview...
废话不多说了,直接给大家贴代码了,具体代码如下所述:
/** * 把一个view的对象转换成bitmap */ private bitmap getviewbitmap(mapview v) { v.clearfocus(); v.setpressed(false); //能画缓存就返回false boolean willnotcache = v.willnotcachedrawing(); v.setwillnotcachedrawing(false); int color = v.getdrawingcachebackgroundcolor(); v.setdrawingcachebackgroundcolor(0); if (color != 0) { v.destroydrawingcache(); } v.builddrawingcache(); bitmap cachebitmap = null; while(cachebitmap == null){ cachebitmap = v.getdrawingmapcache(0, 0, v.getwidth(), v.getheight()); } bitmap bitmap = bitmap.createbitmap(cachebitmap); // restore the view v.destroydrawingcache(); v.setwillnotcachedrawing(willnotcache); v.setdrawingcachebackgroundcolor(color); return bitmap; } public void savemybitmap(string bitname,bitmap mbitmap){ string filename=this.getinnersdcardpath() + "/" + bitname + ".png"; showmessage(filename); file f = new file(filename); try { f.createnewfile(); } catch (ioexception e) { // todo auto-generated catch block log.e("在保存"+filename+"图片时出错:" + e.tostring(),"在保存"+filename+"图片时出错:" + e.tostring()); } fileoutputstream fout = null; try { fout = new fileoutputstream(f); } catch (filenotfoundexception e) { e.printstacktrace(); } mbitmap.compress(bitmap.compressformat.png, 100, fout); try { fout.flush(); } catch (ioexception e) { e.printstacktrace(); } try { fout.close(); } catch (ioexception e) { e.printstacktrace(); } } //缩小 private class buttonnexitclicklistener implements view.onclicklistener { public void onclick(view v) { //showmessage("ok1"); bitmap bitmap=getviewbitmap(mapview); //showmessage("ok2"); savemybitmap("yl",bitmap); //showmessage("ok3"); bitmap.recycle(); showmessage("保存成功"); } }
以上所述是小编给大家介绍的andriod arcgis保存mapview为图片的实例代码,希望对大家有所帮助!
上一篇: Mysql命令大全(完整版)