真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Android實(shí)現(xiàn)截屏功能的實(shí)例

Android 實(shí)現(xiàn)截屏功能的實(shí)例

在蕪湖縣等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需定制,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計(jì),成都全網(wǎng)營(yíng)銷,成都外貿(mào)網(wǎng)站建設(shè),蕪湖縣網(wǎng)站建設(shè)費(fèi)用合理。

實(shí)現(xiàn)代碼:

public class ScreenShot {
  // 獲取指定Activity的截屏,保存到png文件
  private static Bitmap takeScreenShot(Activity activity) {
    // View是你需要截圖的View
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap b1 = view.getDrawingCache();

    // 獲取狀態(tài)欄高度
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;
    Log.i("TAG", "" + statusBarHeight);

    // 獲取屏幕長(zhǎng)和高
    int width = activity.getWindowManager().getDefaultDisplay().getWidth();
    int height = activity.getWindowManager().getDefaultDisplay()
        .getHeight();
    // 去掉標(biāo)題欄
    // Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);
    Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height
        - statusBarHeight);
    view.destroyDrawingCache();
    return b;
  }

  // 保存到sdcard
  private static void savePic(Bitmap b, String strFileName) {
    FileOutputStream fos = null;
    try {
      fos = new FileOutputStream(strFileName);
      if (null != fos) {
        b.compress(Bitmap.CompressFormat.PNG, 90, fos);
        fos.flush();
        fos.close();
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  // 程序入口
  public static void shoot(Activity a) {
    ScreenShot.savePic(ScreenShot.takeScreenShot(a), "sdcard/xx.png");
  }
}

需要注意的是,shoot方法只能在view已經(jīng)被加載后方可調(diào)用。

或者在 以下方法這里調(diào)用。

 @Override
  public void onWindowFocusChanged(boolean hasFocus) {
    // TODO Auto-generated method stub
    super.onWindowFocusChanged(hasFocus);
    ScreenShot.shoot(this);
  }

以上就是Android截屏的實(shí)例,如有疑問(wèn)請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!


網(wǎng)站題目:Android實(shí)現(xiàn)截屏功能的實(shí)例
URL網(wǎng)址:http://weahome.cn/article/gjohce.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部