• [转]Android 屏幕截图 代码


    本文转自:http://www.cnblogs.com/pcstart/archive/2011/09/05/2167187.html

        public static Bitmap getViewBitmap(View v) {
            v.clearFocus(); 
    //
            v.setPressed(false); //
            
    // 能画缓存就返回false
            boolean willNotCache = v.willNotCacheDrawing();
            v.setWillNotCacheDrawing(
    false);
            
    int color = v.getDrawingCacheBackgroundColor();
            v.setDrawingCacheBackgroundColor(
    0);
            
    if (color != 0) {
                v.destroyDrawingCache();
            }
            v.buildDrawingCache();
            Bitmap cacheBitmap 
    = v.getDrawingCache();
            
    if (cacheBitmap == null) {
                
    // Log.e(TAG, "failed getViewBitmap(" + v + ")", new
                
    // RuntimeException());
                return null;
            }
            Bitmap bitmap 
    = Bitmap.createBitmap(cacheBitmap);
            
    // Restore the view
            v.destroyDrawingCache();
            v.setWillNotCacheDrawing(willNotCache);
            v.setDrawingCacheBackgroundColor(color);
            
    return bitmap;
        }

        
    // 保存到sdcard
        
    // savePic(getViewBitmap(v), "sdcard/xx.png");
        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();
            }
        }
  • 相关阅读:
    主流数据库连接池性能比较 hikari druid c3p0 dbcp jdbc
    Dubbo 分布式事务一致性实现
    微服务实现事务一致性实例
    微服务间保持事务一致性
    海量积分数据实时排名处理方式介绍二
    Java两种方法实现循环报数
    MySQL 千万级 数据库或大表优化
    Linux 中 Nginx 重启关闭
    Linux 中 Oracle dmp 文件导入导出
    Linux 中 Oracle 数据库启动和关闭
  • 原文地址:https://www.cnblogs.com/freeliver54/p/2171433.html
Copyright © 2020-2023  润新知