zoukankan      html  css  js  c++  java
  • Android进阶篇截屏操作

        /**截屏操作
         * 
         * 把图片保存到SD卡
         */
        private void ScreenShot(View v,String fileName){
            View view = v.getRootView();
            view.setDrawingCacheEnabled(true);
            Bitmap bitmap = view.getDrawingCache();
            
            FileOutputStream fos = null;
            File dirFile = new File(DIRPATH);
            
            if(!dirFile.exists()){
                dirFile.mkdir();
            }
            
            try {
                fos = new FileOutputStream(new File(DIRPATH + FILENAME));
                if (null != fos) {
                    bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
                    fos.flush();
                    fos.close();
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    截屏操作二:

        public static void screenView(View view,String fileName){
            Bitmap sCoverBitmap = Bitmap.createBitmap(
                    view.getWidth(),view.getHeight(), Config.ARGB_8888);
            Canvas canvas = new Canvas(sCoverBitmap);
            view.draw(canvas);
            
            FileOutputStream fos = null;
            File dirFile = new File(StaticData.PATH);
            
            if(!dirFile.exists()){
                dirFile.mkdir();
            }
            
            try {
                File file = new File(StaticData.PATH,fileName);
                fos = new FileOutputStream(file);
                if (null != fos) {
                    sCoverBitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
                    fos.flush();
                    fos.close();
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
  • 相关阅读:
    2016/09/18
    2016/09/16
    2016/09/15
    2016/09/14
    2016/09/13
    2016/09/12
    2016/09/03
    2016/09/02
    HDU1850 Being a Good Boy in Spring Festival(NIM)
    POJ3070 Fibonacci(矩阵快速幂)
  • 原文地址:https://www.cnblogs.com/gongcb/p/2633648.html
Copyright © 2011-2022 走看看