如何从资源设置位图 [英] How to set a bitmap from resource

查看:23
本文介绍了如何从资源设置位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这看起来很简单,我正在尝试设置位图图像,但是从资源中,我在应用程序中的 drawable 文件夹中有.

This seems simple, I am trying to set a bitmap image but from the resources, I have within the application in the drawable folder.

bm = BitmapFactory.decodeResource(null, R.id.image);

这是正确的吗?

推荐答案

假设您在 Activity 类中调用它

Assuming you are calling this in an Activity class

Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.image);

第一个参数 Resources 是必需的.它通常可以在任何 Context(以及像 Activity 这样的子类)中获得.

The first parameter, Resources, is required. It is normally obtainable in any Context (and subclasses like Activity).

这篇关于如何从资源设置位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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