美文网首页
布局转成图片、android getDrawingCache D

布局转成图片、android getDrawingCache D

作者: 颤抖的闪电 | 来源:发表于2021-04-12 12:11 被阅读0次
    //布局转成图片
        public static Drawable LayoutToDrawable(Context context, View view) {
    
            view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                    View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); // 原始大小
    //        view.buildDrawingCache();
    //        Bitmap bitmap = view.getDrawingCache();
    
            Bitmap b = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
            Canvas c = new Canvas(b);
            view.draw(c);
    
            BitmapDrawable drawable = new BitmapDrawable(context.getResources(), b);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            return drawable;
        }
    

    android – 使用getDrawingCache时是否存在最大...

    相关文章

      网友评论

          本文标题:布局转成图片、android getDrawingCache D

          本文链接:https://www.haomeiwen.com/subject/yxxxlltx.html