Convert a Drawable to bitmap

It's a example to convert a local drawable to bitmap, then display on ImageView.

Convert a Drawable to bitmap


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);

}

}


thumbnail
Title: Convert a Drawable to bitmap
Rating: 100% based on 99998 ratings. 10 user reviews.
Post by

Related articles :

0 comments:

Post a Comment

My Blog List

 
Copyright © 2015. About - Web Version - Mobile Version Sitemap - Contact - Privacy