android - 从位图创建可绘制对象

标签 android bitmap drawable

全部,

按照建议here我需要从我的位图中制作一个可绘制对象。但是当我尝试使用时:

 Drawable d = new Drawable( my_bmp);

它表明这个构造函数已被弃用,取而代之的是:

 Drawable(Bitmap bmp, int resourceId)

我还能如何使用位图制作可绘制对象?

谢谢。

最佳答案

你可以使用

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

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 位图)

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

另请参阅公共(public)构造函数@

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

关于android - 从位图创建可绘制对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23074946/

相关文章:

Android 应用程序在尝试附加调试器时崩溃

android - 为什么 Actionbar title 在按下硬件后退按钮时一直显示 backstack 标题?

Android Studio 1.2 迁移?

android - 使用缩略图作为 picasso 的占位符

android - 使用 xml 可绘制重力右圆

android - 每次程序启动时可绘制对象的显示分辨率密度减半

android - ListView 项目和状态选择器背景可绘制的奇怪行为

android - 无法在手机内存中保存位图

C# 位图到 AVI/WMV 的压缩

c - 使用 Snow Leopard 访问原始图像数据