zoukankan      html  css  js  c++  java
  • android——自定义截图(加水印、logo等)

        /**
         * 获取指定Activity的截屏,保存到png文件
         */
        public static Bitmap takeScreenShot(Activity activity) {
    
            // View是你需要截图的View
            View view = activity.getWindow().getDecorView();
            view.setDrawingCacheEnabled(true);
            view.buildDrawingCache();
            Bitmap b1 = view.getDrawingCache();
    
            // 获取状态栏高度
    //        Rect frame = new Rect();
    //        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    //        int statusBarHeight = frame.top;
            int statusBarHeight = getStatusHeight(activity);
    
            // 获取屏幕长和高
            int width = activity.getWindowManager().getDefaultDisplay().getWidth();
            int height = activity.getWindowManager().getDefaultDisplay()
                    .getHeight();
    
            //二维码图片
            Bitmap erweima = BitmapFactory.decodeResource(activity.getResources(), R.drawable.icon_erweima);
            erweima = Bitmap.createScaledBitmap(erweima, width, width / 5, true);
    
            // 去掉标题栏
            // Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);
            Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height
                    - statusBarHeight);
            view.destroyDrawingCache();
    
            Bitmap bitmap = Bitmap.createBitmap(width, height - statusBarHeight + width / 5, Bitmap.Config.ARGB_8888);
            final Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            Paint bgPaint = new Paint();
            bgPaint.setColor(Color.parseColor("#1e4873"));
            Rect rect = new Rect(0, 0, width, height - statusBarHeight + width / 5);
            canvas.drawRect(rect, bgPaint);
    
            int h = 0;
            canvas.drawBitmap(b, 0, h, paint);
            h += height - statusBarHeight;
            canvas.drawBitmap(erweima, 0, h, paint);
    
    //        savePic(bitmap, "/sdcard/screen_test.png");
    
            return bitmap;
        }

    获取状态栏高度:

    http://www.cnblogs.com/shoneworn/p/8026587.html

  • 相关阅读:
    快速排序
    冒泡排序
    mysql 拷贝表插入新的表
    http协议
    nginx错误日志error_log日志级别
    MySQL数据库远程访问的权限
    mysql create database 指定utf-8编码
    MYSQL日志
    linux常用命令
    java学习--基础知识进阶第六天--集合&迭代器、增强for & 泛型、常见数据结构、List子体系
  • 原文地址:https://www.cnblogs.com/shoneworn/p/8026604.html
Copyright © 2011-2022 走看看