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

  • 相关阅读:
    JSONP
    懒加载
    HTTP 状态代码
    java4中创建内对象的方法
    注册jdbc驱动程序的三种方式
    java Clone()克隆
    Class.forName()的理解
    Bitmap介绍
    前端-PC端瀑布流【10张图】
    百度小程序-图片画廊-使用previewImage方法实现
  • 原文地址:https://www.cnblogs.com/shoneworn/p/8026604.html
Copyright © 2011-2022 走看看