2012-11-28 39 views
1

有時它有效,有時它不。我分享這張照片在Facebook上,有時它是確定:Android截圖 - 部分黑色谷歌地圖

Picture ok - without blackness

有時則是偏黑的(只有谷歌地圖!):

Picture not OK - partial black Google map

我有一個單獨的線程執行此屏幕截圖:

new Thread() { 
    @Override 
    public void run() {      
     // Get root view 
     View view = mapView.getRootView(); 
     view.setDrawingCacheEnabled(true); 

     // Create the bitmap to use to draw the screenshot 
     final Bitmap bitmap = Bitmap.createBitmap(
       getWindowManager().getDefaultDisplay().getWidth(), getWindowManager().getDefaultDisplay().getHeight(), Bitmap.Config.ARGB_4444); 
     final Canvas canvas = new Canvas(bitmap); 

     // Get current theme to know which background to use 
     final Theme theme = activity.getTheme(); 
     final TypedArray ta = theme 
      .obtainStyledAttributes(new int[] { android.R.attr.windowBackground }); 
     final int res = ta.getResourceId(0, 0); 
     final Drawable background = activity.getResources().getDrawable(res); 

     // Draw background 
     background.draw(canvas); 

     // Draw views 
     view.draw(canvas); 

     ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
     bitmap.compress(Bitmap.CompressFormat.PNG, 90, baos); //bm is the bitmap object 
     byte[] b = baos.toByteArray(); 

     Bundle params = new Bundle(); 
     params.putByteArray("source", b); 
     params.putString("message", "genie in a bottle"); 
     try { 
      //String resp = 
        facebook.request("me/photos", params, "POST"); 
     } catch (FileNotFoundException e) { 
      throw new RuntimeException(e); 
     } catch (MalformedURLException e) { 
      throw new RuntimeException(e); 
     } catch (IOException e) { 
      throw new RuntimeException(e); 
     } 
    } 

}.start(); 

回答

0

您可以直接從scr創建對象Bitmap een使用:

bitmap = Bitmap.createBitmap(view.getDrawingCache()); 

問候。