无法获取的LinearLayout的位图与其子沿意见 [英] Unable to get the bitmap of a linearlayout along with its child views

查看:154
本文介绍了无法获取的LinearLayout的位图与其子沿意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建从LinearLayout中位图具有下列code

I am creating the bitmap from a linearlayout with the following code

公共静态位图loadBitmapFromView(视图v){

public static Bitmap loadBitmapFromView(View v ) {

    //Bitmap b = Bitmap.createBitmap( v.getLayoutParams.width, v.getLayoutParams.height, Bitmap.Config.ARGB_8888);
    Bitmap b = Bitmap.createBitmap( v.getLayoutParams.width, v.getLayoutParams.height, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
    v.draw(c);
    return b;
}

但我不能看到它的意见
所有我看到的是一个很大的灰色屏幕

but i can not see the views in it all i can see is a big grey screen

试图在这个问题的答案也是<一个href=\"http://stackoverflow.com/questions/4960753/android-problems-converting-viewgroup-with-children-into-bitmap\">Android问题的ViewGroup转换有子女入位图但仍无法正常工作

have tried the answer at this question also Android Problems Converting ViewGroup with Children into Bitmap but still not working

我的看法是从XML膨胀
当我使用上面我所提到的code得到强制关闭了空指针异常
如果我提的宽度和高度有些像200号,200那么我能看到灰色的背景不仅没有认为它。

My view is being inflated from xml and when i use the code mentioned above i get force close for null pointer exception and if i mention the width and height to some number like 200 , 200 then i am able to see the grey background only not the view in it.

推荐答案

您需要测量像

v.measure(
      MeasureSpec.makeMeasureSpec(v.getLayoutParams().width,MeasureSpec.EXACTLY),
      MeasureSpec.makeMeasureSpec(v.getLayoutParams().height, MeasureSpec.EXACTLY));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight()
        ,Bitmap.Config.RGB_565);
Canvas c = new Canvas(b);
v.draw(c);

这篇关于无法获取的LinearLayout的位图与其子沿意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆