package com.example.androidcolor;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.ImageView;
public class MainActivity extends Activity {
ImageView targetImage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
targetImage = (ImageView)findViewById(R.id.target);
//Load bitmap locally in APK
Bitmap srcBitmapLocal = BitmapFactory.decodeResource(
getApplicationContext().getResources(),
R.drawable.ic_launcher);
targetImage.setImageBitmap(srcBitmapLocal);
}
}
Friday, September 28, 2012
Convert a Drawable to bitmap
It's a example to convert a local drawable to bitmap, then display on ImageView.
Subscribe to:
Post Comments (Atom)
2 comments:
If there are multiple images in the drawable folder, then how will each image be retrieved and converted into a bitmap?
It is specified in the second parameter in BitmapFactory.decodeResource() calling.
Post a Comment