最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)截屏并保存操作功能

 更新時(shí)間:2015年12月23日 10:11:40   作者:cjjky  
這篇文章主要介紹了Android實(shí)現(xiàn)截屏操作功能,即Android中截取當(dāng)前屏幕的功能,感興趣的小伙伴們可以參考一下

該篇文章是說明在Android手機(jī)或平板電腦中如何實(shí)現(xiàn)截取當(dāng)前屏幕的功能,并把截取的屏幕保存到SDCard中的某個(gè)目錄文件夾下面。
實(shí)現(xiàn)的代碼如下:

/** 
 * 獲取和保存當(dāng)前屏幕的截圖 
 */ 
private void GetandSaveCurrentImage() 
{ 
 //1.構(gòu)建Bitmap 
 WindowManager windowManager = getWindowManager(); 
 Display display = windowManager.getDefaultDisplay(); 
 int w = display.getWidth(); 
 int h = display.getHeight(); 
  
 Bitmap Bmp = Bitmap.createBitmap( w, h, Config.ARGB_8888 );  
  
 //2.獲取屏幕 
 View decorview = this.getWindow().getDecorView();  
 decorview.setDrawingCacheEnabled(true);  
 Bmp = decorview.getDrawingCache();  
  
 String SavePath = getSDCardPath()+"/AndyDemo/ScreenImage"; 
 
 //3.保存Bitmap  
 try { 
  File path = new File(SavePath); 
  //文件 
  String filepath = SavePath + "/Screen_1.png"; 
  File file = new File(filepath); 
  if(!path.exists()){ 
   path.mkdirs(); 
  } 
  if (!file.exists()) { 
   file.createNewFile(); 
  } 
   
  FileOutputStream fos = null; 
  fos = new FileOutputStream(file); 
  if (null != fos) { 
   Bmp.compress(Bitmap.CompressFormat.PNG, 90, fos); 
   fos.flush(); 
   fos.close();  
    
   Toast.makeText(mContext, "截屏文件已保存至SDCard/AndyDemo/ScreenImage/下", Toast.LENGTH_LONG).show(); 
  } 
 
 } catch (Exception e) { 
  e.printStackTrace(); 
 } 
} 
 
 /** 
 * 獲取SDCard的目錄路徑功能 
 * @return 
 */ 
private String getSDCardPath(){ 
 File sdcardDir = null; 
 //判斷SDCard是否存在 
 boolean sdcardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); 
 if(sdcardExist){ 
  sdcardDir = Environment.getExternalStorageDirectory(); 
 } 
 return sdcardDir.toString(); 
} 

由于要對SDCard進(jìn)行操作,所以別忘記了在manifest.xml文件中賦以對SDCard的讀寫權(quán)限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

希望本文所述對大家學(xué)習(xí)Android軟件編程有所幫助。

相關(guān)文章

最新評論

武清区| 嘉祥县| 资中县| 甘南县| 江孜县| 图们市| 仲巴县| 鞍山市| 扎赉特旗| 黎平县| 宁德市| 昆山市| 益阳市| 临泉县| 黄浦区| 浦北县| 陵水| 尉犁县| 木兰县| 手机| 昭苏县| 利津县| 清新县| 宁都县| 资中县| 阳新县| 武功县| 米泉市| 丰县| 莱西市| 樟树市| 略阳县| 荆门市| 罗甸县| 济源市| 永登县| 治多县| 长沙县| 宜良县| 郁南县| 武威市|