将Android活动布局转换为任何图像格式

将Android活动布局转换为任何图像格式,android,android-layout,android-intent,android-emulator,android-listview,Android,Android Layout,Android Intent,Android Emulator,Android Listview,Am使用线性布局,其尺寸大于手机屏幕尺寸。具有可见性的对象是隐藏的 那个布局里面有一些内容。我需要采取出口,作为图像格式完整的活动见参考图片我附加 如何获得完整的活动图像(jpeg或任何其他) 我尝试了这个代码,但我不能得到全幅图像。我只看到了手机屏幕 请更正它 View layoutview = (LinearLayout) findViewById(R.id.layout_outer); layoutview.setDrawingCacheEnabled(true);

Am使用线性布局,其尺寸大于手机屏幕尺寸。具有可见性的对象是隐藏的 那个布局里面有一些内容。我需要采取出口,作为图像格式完整的活动见参考图片我附加

如何获得完整的活动图像(jpeg或任何其他)

我尝试了这个代码,但我不能得到全幅图像。我只看到了手机屏幕

请更正它

View  layoutview = (LinearLayout) findViewById(R.id.layout_outer);
        layoutview.setDrawingCacheEnabled(true);
        Bitmap bimg = layoutview.getDrawingCache();             

        File imgPath = new File("/sdcard/sample.png");
        FileOutputStream fOs = null;
        try {
            fOs = new FileOutputStream(imgPath);
            bimg.compress(Bitmap.CompressFormat.PNG, 100, fOs);
            fOs.flush();
            fOs.close();
            btndsbExport.setVisibility(View.VISIBLE);


        }catch (FileNotFoundException e) {
            e.printStackTrace();


    enter code here
        } catch (Exception e) {
            e.printStackTrace();

        }

也许可以尝试创建一个新位图、一个新画布,然后将位图传递给构造函数。然后使用新画布作为参数调用views.draw方法。我还没试过,所以我只把它作为评论:)你说的全幅图像是什么意思?您的图像宽度是否与设备宽度不匹配?我的意思是,我的设备宽度为240*800,但线性布局宽度为1200*800。此布局具有背景图像或任何网格视图来放置图像或任何图像。如果使用上述代码,我只能看到手机屏幕宽度以下的图像。。图像的剩余部分被剪切。。。我希望现在你明白我的意思了,试试layoutview.setPersistentDrawingCache(ViewGroup.PERSISTENT\u ALL\u CACHES),看看是否有帮助。我猜setDrawingCacheEnabled(true)只缓存可见部分。您也可以尝试使用持久滚动缓存。但是对于布局,我没有任何滚动,只是背景渲染和隐藏屏幕的可见性。。