Android Internet access to image methods on the web

Source: Internet
Author: User
Tags error code getmessage sendmsg

To get the picture on the network, first of all have access to the network, this no longer write, the previous article has written, there is no longer the layout of the writing, is written is also a simple layout, not much meaning, directly on the core code:

This is a simple class that I use to get pictures on the web.

public static Bitmap GetImage (String Url) throws Exception {

try {

URL url = new url (URL);

String responsecode = Url.openconnection (). Getheaderfield (0);

if (Responsecode.indexof ("M") < 0)

throw new Exception ("Picture file does not exist or path error, error code:" + responsecode);

Return Bitmapfactory.decodestream (Url.openstream ());

catch (IOException e) {

TODO auto-generated Catch block

throw new Exception (E.getmessage ());

}

}

This class returns a Bitmap object,

The following is a simple call to a class:

Directly on the code:

Bitmap Mbitmap;

Get Pictures directly:

private void Refreshdb () {

try {

Sendmsg (Declare.start, "Loading pictures ...");

Mbitmap = downfile.getimage (picture address);

Sendmsg (Declare.stop, "");

catch (Exception e) {

TODO auto-generated Catch block

Sendmsg (Declare.error, E.getmessage ());

}

Here with a simple scroll bar, indicating that the current program is executing, through the way of sending a message, the specific no longer write, that message headless this core code implementation.

To execute after the load completes:

Mimageview1.setimagebitmap (MBITMAP);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.