Android programming for easy access to pictures on the Web _android

Source: Internet
Author: User
Tags getmessage sendmsg

An example of this article is a simple way to get a picture on a network with Android programming. Share to everyone for your reference, specific as follows:

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) < 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 picture directly:
private void Refreshdb () {
  try {
    sendmsg (declare.start, loading picture ...);
    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);

For more information on Android-related content readers can view the site: "Android graphics and image processing skills summary", "Android Development introduction and Advanced Course", "Android debugging techniques and common problems solution summary", " Android Multimedia How-to Summary (audio, video, audio, etc), summary of Android Basic components usage, Android View tips Summary, Android layout layout tips and a summary of Android controls usage

I hope this article will help you with the Android program.

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.