Exemplo n.º 1
0
 /** 截图listview * */
 public static Bitmap getbBitmap(ListView listView) {
   int h = 0;
   Bitmap bitmap = null;
   // 获取listView实际高度
   for (int i = 0; i < listView.getChildCount(); i++) {
     h += listView.getChildAt(i).getHeight();
   }
   Log.d(TAG, "实际高度:" + h);
   Log.d(TAG, "list 高度:" + listView.getHeight());
   // 创建对应大小的bitmap
   bitmap = Bitmap.createBitmap(listView.getWidth(), h, Bitmap.Config.ARGB_8888);
   final Canvas canvas = new Canvas(bitmap);
   listView.draw(canvas);
   // 测试输出
   FileOutputStream out = null;
   try {
     out = new FileOutputStream("/sdcard/screen_test.png");
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   }
   try {
     if (null != out) {
       bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
       out.flush();
       out.close();
     }
   } catch (IOException e) {
     // TODO: handle exception
   }
   return bitmap;
 }
Exemplo n.º 2
0
  public static Bitmap getViewBitmap(View v) {
    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) {
      Log.e("TTTTTTTTActivity", "failed getViewBitmap(" + v + ")");
      return null;
    }

    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

    // Restore the view
    v.destroyDrawingCache();
    v.setWillNotCacheDrawing(willNotCache);
    v.setDrawingCacheBackgroundColor(color);

    return bitmap;
  }
Exemplo n.º 3
0
 /** 把View对象转换成bitmap */
 public static Bitmap convertViewToBitmap(View view) {
   view.measure(
       MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
       MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
   view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
   view.buildDrawingCache();
   Bitmap bitmap = view.getDrawingCache();
   if (bitmap != null) {
     System.out.println("这不是nullde1");
     Log.d("nullde1", "nullde1");
   } else {
     System.out.println("这nullnulllnulnlul");
   }
   return bitmap;
 }