Load an ImageView by URL in Android


Image referenced by URL in an ImageView, getting image from url and set on imageview, then here is the some idea, which may helpful .

Here is the some snap codes:

// show The Image on button load click event
new DownloadImageTask((ImageView) findViewById(R.id.imageView1))
            .execute("http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png");
}

public void onClick(View v) {
    startActivity(new Intent(this, IndexActivity.class));
    finish();

}

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    ImageView bmImage;

    public DownloadImageTask(ImageView bmImage) {
        this.bmImage = bmImage;
    }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return mIcon11;
    }

    protected void onPostExecute(Bitmap result) {
        bmImage.setImageBitmap(result);
    }
}
write permission on  AndroidManifest.xml to access the internet.

<uses-permission android:name="android.permission.INTERNET" />

 and convert whole ImageView to Bitmap from this code:

imageView.buildDrawingCache();
Bitmap bmap = imageView.getDrawingCache();

other examples:

http://www.learn2crack.com/2014/06/android-load-image-from-internet.html

http://www.androidhive.info/2012/07/android-loading-image-from-url-http/

http://theopentutorials.com/tutorials/android/imageview/android-how-to-load-image-from-url-in-imageview/

http://belencruz.com/2012/11/load-imageview-from-url-in-android/

Happy Coding!!!
Load an ImageView by URL in Android Load an ImageView by URL in Android Reviewed by D Kshetri on 12:27 AM Rating: 5

No comments:

Powered by Blogger.