Public static Bitmap getImage (String Url) throws Exception {
Try {
URL url = new URL (Url );
String responseCode = url. openConnection (). getHeaderField (0 );
If (responseCode. indexOf ("200") <0)
Throw new Exception ("the image file does not exist or the path is incorrect. 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 the class:
Directly run the Code:
Bitmap mBitmap;
// Directly retrieve the image:
Private void RefreshDB (){
Try {
SendMSG (Declare. START, "loading image ......");
MBitmap = DownFile. getImage (image address );
SendMSG (Declare. STOP ,"");
} Catch (Exception e ){
// TODO Auto-generated catch block
SendMSG (Declare. ERROR, e. getMessage ());
}
A simple scroll bar is provided here, indicating that the current program is being executed and implemented by sending messages. The core code is not written anymore.
Run the following command after loading:
MImageView1.setImageBitmap (mBitmap );