android 如何获取launcher的workspace中的每一个celllayout的位图???

我要做一个3D旋转桌面,现在已经绘制好立方体,往上面贴好纹理了,不过纹理是其他图片,现在我想要获取launcher的workspace中的每一个celllayout的位图,然后将其作为纹理贴到立方体上。
   也就是说,我现在不知道如何将workspace中的每一个分屏view(celllayout)转换成位图。
   我已经尝试过的方法有两个,都不行: 注:下面的cell1来自launcher.xml中的<include android:id="@+id/cell1" layout="@layout/workspace_screen" />这一句,具体见层级观察器的截图。
   1. [code=Java]
View view = findViewById(R.id.cell1);
    Bitmap bit = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);//这一句话报错,说view的宽高是0.
    Canvas c = new Canvas(bit);
    view.draw(c);
    if(bit==null)
          Log.v(TAG,"mBitmap is null");
    else
    Log.v(TAG,"mBitmap is not null");


 [/code] 


   2.[code=Java]
View tempView=(View)findViewById(R.id.cell1);
     tempView.setDrawingCacheEnabled(true);    
     tempView.measure( MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),     
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));//这一句话报错,说tempView大小不确定神马的。     

     tempView.layout(0, 0, tempView.getMeasuredWidth(),tempView.getMeasuredHeight());      
     tempView.buildDrawingCache();               
     mBitmap[0]= tempView.getDrawingCache();  
     if(mBitmap[0]==null)
        Log.v(TAG,"mBitmap is null");
     
[/code]
[img=https://img-my.csdn.net/uploads/201205/24/13378284_7309.jpg][/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值