Andriod arcgis保存Mapview为图片的实例代码

废话不多说了,直接给大家贴代码了,具体代码如下所述:

/**
* 把一个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为图片的实例代码,希望对大家有所帮助!

(0)

相关推荐

  • Andriod 资源文件之存取操作

    废话不多说了,直接给大家贴代码了.具体代码如下所述: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="mat

  • Andriod 自定义控件之音频条

    今天我们实现一个直接继承于View的全新控件.大家都知道音乐播放器吧,在点击一首歌进行播放时,通常会有一块区域用于显示音频条,我们今天就来学习下,播放器音频条的实现. 首先我们还是先定义一个类,直接继承于View,并重写它的构造方法,并初始化一个画笔,这和上一节是同样的道理.直接贴出代码: public class AudioBar extends View{ private Paint mTextPaint; public AudioBar(Context context) { this(co

  • Andriod学习教程之滑动布局(14)

    本文实例为大家分享了Andriod滑动布局的具体代码,供大家参考,具体内容如下 MainActivity.java代码: package siso.swipelayoutdemo; import android.app.Activity; import android.content.Intent; import android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.B

  • Andriod 读取网络图片实例代码解析

    Android手机上,我们常用ImageView显示图片,我们本章获取网络图片并显示在ImageView中. 一.设计界面 1.布局文件 打开res/layout/activity_main.xml文件. 输入以下代码: <?xml version="." encoding="utf-"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu

  • Andriod开发中常见问题

    本文为大家总结了Andriod开发中常遇到的问题,供大家学习,具体内容如下 1.Andriod中布局中引用布局的问题 (使用如下方法即可,布局中引用布局可以起到节省资源的问题) <LinearLayout> <include layout="@layout/buttom"> </LinearLayout> 2.如何判断你的手机版本是不是4.0以上 if(Android.os.Build.VERSION.SDK_INT>10) 3.屏幕切换问题和

  • Andriod 获取电池的信息实例代码

    具体代码如下所示: <?xml version="1.0"?> <LinearLayout android:orientation="vertical" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"

  • 代码从windows下visual studio到andriod平台迁移实现步骤

    代码从windows下visual studio到andriod平台迁移实现步骤: 前言 前言也是迁言,从windows的visual studio 2012平台迁移到Android平台上,需用修改挺多的代码和需用注意地方. 我们当然的平台当初就考虑了其他平台跨平台的应用问题,所以一开始在windows下就是用cmake来完成工程的建立的,cMakeLists.txt文件都做了一些处理,但是此时只是更针对或说首先保证windows下的编译和使用. 谨此做个记录. 1. modify cMakeL

  • Andriod开发中引入jar包的正确方式介绍

    andriod中如果引入jar包的方式不对就会出现一些奇怪的错误. 工作的时候恰好有一个jar包需要调用,结果用了很长时间才解决出现的bug. 刚开始是这样引用的(eclipse): 右键工程,Build path,java build path, 选择libraries,在右边的按钮中点击"Add External JARs", 然后选择合适的jar包(大部分人应该会这样做). 结果控制台立刻报错:conversion to dalvik format failed with err

  • Java实现Andriod带看括弧的计算器代码

    废话不多说了,一切尽在代码中,具体代码如下所示: 界面 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_par

  • Andriod arcgis保存Mapview为图片的实例代码

    废话不多说了,直接给大家贴代码了,具体代码如下所述: /** * 把一个View的对象转换成bitmap */ private Bitmap getViewBitmap(MapView v) { v.clearFocus(); v.setPressed(false); //能画缓存就返回false boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); int color = v.getDr

  • Java生成表格图片的实例代码

    主要代码: /** * 生成图片 * @param cellsValue 以二维数组形式存放 表格里面的值 * @param path 文件保存路径 */ public void myGraphicsGeneration(String cellsValue[][], String path) { // 字体大小 int fontTitileSize = 15; // 横线的行数 int totalrow = cellsValue.length+1; // 竖线的行数 int totalcol =

  • AngularJs上传前预览图片的实例代码

    在工作中,使用AngularJs进行开发,在项目中,经常会遇到上传图片后,需在一旁预览图片内容,之前查了一些资料,结合实践,得出一种比较实用的方法,相对简化版,在这里记录一下,如有不同看法,欢迎一起沟通,一起成长. demo.html: <!doctype html> <html ng-app="myTestCtrl"> <head> <meta charset="UTF-8"> <title>demo&l

  • java图片添加水印实例代码分享

    本文为大家介绍了java图片添加水印实例代码,java实现水印还是非常方便的,水印可以是图片或者文字,具体内容如下 package michael.io.image; import java.awt.AlphaComposite; import java.awt.Graphics2D; import java.awt.Image; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.io

  • Android中复制图片的实例代码

    activity_main.xml中的配置 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent&quo

  • Python爬虫爬取一个网页上的图片地址实例代码

    本文实例主要是实现爬取一个网页上的图片地址,具体如下. 读取一个网页的源代码: import urllib.request def getHtml(url): html=urllib.request.urlopen(url).read() return html print(getHtml(http://image.baidu.com/search/flip?tn=baiduimage&ie=utf-8&word=%E5%A3%81%E7%BA%B8&ct=201326592&am

  • python使用pil库实现图片合成实例代码

    本文研究的主要是python PIL实现图片合成的相关内容,具体介绍如下,分享实例代码. 在项目中需要将两张图片合在一起.遇到两种情况,一种就是两张非透明图片的合成, 一种是涉及到透明png的合成. 相关API见 http://pillow.readthedocs.io/en/latest/reference/Image.html 第一种情况,直接将两张图片合在一起就可以了.如下图所示,将两张图片合在一起 += 详细代码 from PIL import Image #加载底图 base_img

  • 微信小程序之批量上传并压缩图片的实例代码

    具体内容如下所示: 首先,要在.wxml文件里面创建一个canvas,作用是承载压缩的图片,以供上传的时候获取 这个canvas不能隐藏,否则没效果,可以将其移至屏幕外. <canvas canvas-id='attendCanvasId' class='myCanvas'></canvas> 然后呢,就是.js文件里面的方法了 // 点击加_压缩 takePhoto: function () { var that = this; let imgViewList = that.da

  • android 实现APP中改变头像图片的实例代码

    具体代码如下所示: package com.example.studyapplication.fragment; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory

  • java实现爬虫爬网站图片的实例代码

    第一步,实现 LinkQueue,对url进行过滤和存储的操作 import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; public class LinkQueue { // 已访问的 url 集合 private static Set<String> visitedUrl = Collecti

随机推荐