从位图创建可绘制对象 [英] Create drawable from bitmap

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

问题描述

全部

按照建议的此处,我需要使用我的位图.但是当我尝试使用时:

As suggested here I need to make a drawable out of my bitmap. But when I tried to use:

 Drawable d = new Drawable( my_bmp);

表明不赞成使用此构造方法,而推荐使用:

it shows that this constructor is deprecated in favour of:

 Drawable(Bitmap bmp, int resourceId)

我还能如何使用位图绘制图形?

How else I can make a drawable out of bitmap?

谢谢.

推荐答案

您可以使用

Drawable d = new BitmapDrawable(getResources(), my_bmp);

一个可包装位图的Drawable,可以平铺,拉伸或 对齐.您可以从文件路径(输入)创建BitmapDrawable 流,通过XML膨胀或从Bitmap对象.

A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. You can create a BitmapDrawable from a file path, an input stream, through XML inflation, or from a Bitmap object.

BitmapDrawable(Resources res, Bitmap bitmap)

根据位图创建可绘制对象,并根据以下内容设置初始目标密度 资源的显示指标.

Create drawable from a bitmap, setting initial target density based on the display metrics of the resources.

也看一看公共构造函数@

Also look a the public constructors @

http://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html

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

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