Andriod arcgis保存Mapview為圖片的實例代碼
更新時間:2016年03月07日 14:50:11 作者:gisoracle
這篇文章主要介紹了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為圖片的實例代碼,希望對大家有所幫助!
相關文章
Android Flutter實現(xiàn)3D動畫效果示例詳解
在Flutter中提供了AnimatedWidget組件用于構建可復用的動畫組件。本文我們用AnimatedWidget來實現(xiàn)組件的3D旋轉效果,感興趣的可以了解一下2022-03-03
使用ViewPager實現(xiàn)高仿launcher左右拖動效果
今天用ViewPager這個類實現(xiàn)了同樣的左右拖動效果,這樣代碼更少,但是效果是一樣的,ViewPager是實現(xiàn)左右兩個屏幕平滑地切換的一個類,它是Google提供的,有需要的朋友可以了解下2013-01-01
Android開發(fā)之ListView、GridView 詳解及示例代碼
本文主要介紹Android開發(fā)之ListView、GridView,這里整理了相關資料及簡單示例代碼,幫助大家學習參考,有需要的小伙伴可以參考下2016-08-08
Android?Compose之Animatable動畫停止使用詳解
這篇文章主要為大家介紹了Android?Compose之Animatable動畫停止使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-03-03
Flutter Widget移動UI框架使用Material和密匙Key實戰(zhàn)
這篇文章主要為大家介紹了Flutter Widget移動UI框架使用Material和密匙Key實戰(zhàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-12-12
Android開發(fā)之Notification通知用法詳解
這篇文章主要介紹了Android開發(fā)之Notification通知用法,結合實例形式較為詳細的分析了Notification通知的功能、參數(shù)、定義及使用方法,需要的朋友可以參考下2016-11-11

