这篇文章主要介绍了Andriod arcgis保存Mapview为图片的实例代码 的相关资料,需要的朋友可以参考下
这篇文章主要介绍了Andriod arcgis保存Mapview为图片的实例代码 的相关资料,需要的朋友可以参考下
这篇文章主要介绍了Andriod arcgis保存Mapview为图片的实例代码 的相关资料,需要的朋友可以参考下
废话不多说了,直接给大家贴代码了,具体代码如下所述:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/*** 把一个view的对象转换成bitmap*/private bitmap getviewbitmap(mapview v) {v.clearfocus();v.setpressed(false);//能画缓存就返回falseboolean 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 viewv.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 blocklog.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为图片的实例代码,希望对大家有所帮助!
发表评论