我怎么可以转换视角的一个绘制对象? [英] How can I convert a View to a Drawable?

查看:83
本文介绍了我怎么可以转换视角的一个绘制对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查看,我想将其转换成图像,以便存储在某个地方。 但我怎么可以把这个查看到图像?

I have a View and I want to convert it into an image in order to store it somewhere. But how can I convert this View to an image?

推荐答案

看看这个观点,并存储在SD卡的取像。

Try this for take image of view and store in sd card..

View view = TextView.getRootView();
//You can use any view of your View instead of TextView

if (view != null)
{
    System.out.println("view is not null.....");
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    BitMap bm = view.getDrawingCache();

    try
    {
        if (bm != null)
        {
            String dir = Environment.getExternalStorageDirectory().toString();
            System.out.println("bm is not null.....");
            OutputStream fos = null;
            File file = new File(dir,"sample.JPEG");
            fos = new FileOutputStream(file);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            bm.compress(Bitmap.CompressFormat.JPEG, 50, bos);
            bos.flush();
            bos.close();
        }
    }
    catch(Exception e)
    {
        System.out.println("Error="+e);
        e.printStackTrace();
    }
}

这篇关于我怎么可以转换视角的一个绘制对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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