繁体   English   中英

安卓截图——局部黑色谷歌地图

[英]Android taking a screenshot - partial black Google map

有时它有效,有时它不起作用。 我在 Facebook 上分享这张照片,有时还可以:

图片正常 - 没有黑度

有时它是部分黑色(只有谷歌地图!):

图片不正常 - 偏黑谷歌地图

我有一个单独的线程来做这个截图:

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();

您可以使用以下命令直接从屏幕创建Bitmap对象:

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

问候。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM