从视图创建图像 [英] Creating Image from View

查看:84
本文介绍了从视图创建图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从android中的视图创建图像,并使用以下代码在其底部添加另一个图像

I am creating an image from a view in android and adding another image to the bottom of it with the code below

CardView card_view = (CardView) tmps.findViewById(R.id.card_view);
Bitmap b = Bitmap.createBitmap(card_view.getWidth(), card_view.getHeight() + 112, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
card_view.draw(c);
c.translate(card_view.getWidth() / 2 - 51, card_view.getHeight() + 10);
Drawable d = context.getResources().getDrawable(R.drawable.share_logo);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
d.draw(c);

现在,当我将图像添加到底部(R.drawable.share_logo)时,它将出现在黑色背景。如何为整个画布创建白色填充的rect作为背景?

Now when i add the image to the bottom (R.drawable.share_logo) it is coming on a black background. how do I create a white filled rect as background for the entire canvas?

推荐答案

尝试以下代码:

 public static Bitmap loadBitmapFromView(View v) {
        Bitmap b = Bitmap.createBitmap( v.getLayoutParams().width,  v.getLayoutParams().height, Bitmap.Config.ARGB_8888);                
        Canvas c = new Canvas(b);
        v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
        v.draw(c);
        return b;
    }


CardView card_view = (CardView) tmps.findViewById(R.id.card_view);
Bitmap bitmap = loadBitmapFromView(card_view);

这篇关于从视图创建图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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