Search this blog

How to access image resources programatically android

Images resources are encapsulated in the class BitmapDrawable. To access a graphic resource file called /res/drawable/logo.png, you would use the getDrawable() method, as follows:

BitmapDrawable logoBitmap =

Most of the time, however, you don’t need to load a graphic directly. Instead, you
can use the resource identifier as an attribute on a control such as an ImageView
control. The following code, for example, sets and loads the logo.png graphic into
an ImageView control named LogoImageView, which must be defined within the

ImageView logoView = (ImageView)findViewById(;


Post a Comment