Here is a simple example showing how to load an image stores in assets folder in android?

package com.coderzheaven.pack;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;

public class LoadImageFromAssetsDemo extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        // Get the AssetManager
        AssetManager manager = getAssets();

        // Read a Bitmap from Assets
        try {
        	InputStream open = manager.open("icon.png");
        	Bitmap bitmap = BitmapFactory.decodeStream(open);
        	// Assign the bitmap to an ImageView in this layout
        	ImageView view = (ImageView) findViewById(R.id.ImageView01);
        	view.setImageBitmap(bitmap);
        } catch (IOException e) {
        	e.printStackTrace();
        } 
    }
}

Done.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.