• Android视图的截图


    在pc上的截图软件很多,但是android上的比较少,所以就自己写了一个,下面时截图软件的核心代码private Bitmap getViewBitmap(View v) { // 将一个View转化成一张图片

            v.clearFocus(); // 清除视图焦点
    v.setPressed(false);// 将视图设为不可点击

    boolean willNotCache = v.willNotCacheDrawing(); // 返回视图是否可以保存他的画图缓存
    v.setWillNotCacheDrawing(false);

    // Reset the drawing cache background color to fully transparent
    // for the duration of this operation //将视图在此操作时置为透明
    int color = v.getDrawingCacheBackgroundColor(); // 获得绘制缓存位图的背景颜色
    v.setDrawingCacheBackgroundColor(0); // 设置绘图背景颜色
    if (color != 0) { // 如果获得的背景不是黑色的则释放以前的绘图缓存
    v.destroyDrawingCache(); // 释放绘图资源所使用的缓存
    }
    v.buildDrawingCache(); // 重新创建绘图缓存,此时的背景色是黑色
    Bitmap cacheBitmap = v.getDrawingCache(); // 将绘图缓存得到的,注意这里得到的只是一个图像的引用
    if (cacheBitmap == null) {
    return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // 将位图实例化
    // Restore the view //恢复视图
    v.destroyDrawingCache();// 释放位图内存
    v.setWillNotCacheDrawing(willNotCache);// 返回以前缓存设置
    v.setDrawingCacheBackgroundColor(color);// 返回以前的缓存颜色设置
    return bitmap;
    }

    转自:http://xiangqianppp-163-com.iteye.com/blog/1457688

  • 相关阅读:
    page指令
    CMD设IP
    JDBC的几种驱动
    Python的闭包使用
    1189. 扫雷游戏
    1287. 递增的三元子序列
    Pip安装使用国内源的两种方法
    Python Classmethod和Staticmethod函数
    Git提交远程仓库
    Git分支管理
  • 原文地址:https://www.cnblogs.com/shanzei/p/2412746.html
Copyright © 2020-2023  润新知