Android Sets the path to ImageView

ImageView is a frequently used component in Android programs, which displays an image on the screen.

Define an ImageView in UI xml as follows:
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.myimage);
ImageView image1
= (ImageView) findViewById(R.myImage.image);
//Bitmap bitmap = getLoacalBitmap("/aa/aa.jpg "); //Get pictures from local
Bitmap bitmap =
getHttpBitmap(
"http://blog.3gstdy.com/wp-content/themes/twentyten/images/headers/path.jpg") ;
//Get pictures from the Internet
image1 .setImageBitmap(bitmap); //Set Bitmap
}
/**
* Load local pictures
*
http://bbs.3gstdy.com
*
@param url
*
@return
*/
public static Bitmap getLoacalBitmap(String url) {
try {
FileInputStream fis
= new FileInputStream(url);
return BitmapFactory.decodeStream(fis);
}
catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
}
/**
* Get pictures from the server
*
http://bbs.3gstdy.com
*
@param url
*
@return
*/
public static Bitmap getHttpBitmap(String url) {
URL myFileUrl
= null;
Bitmap bitmap
= null;
try {
Log.d(TAG, url);
myFileUrl
= new URL(url);
}
catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn
= (HttpURLConnection) myFileUrl.openConnection();
conn.setConnectTimeout(
0);
conn.setDoInput(
true);
conn.connect();
InputStream is
= conn.getInputStream();
bitmap
= BitmapFactory.decodeStream(is);
is.close();
}
catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}

Define an ImageView in UI xml as follows:

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.myimage);
ImageView image1
= (ImageView) findViewById(R.myImage.image);
//Bitmap bitmap = getLoacalBitmap("/aa/aa.jpg "); //Get pictures from local
Bitmap bitmap =
getHttpBitmap(
"http://blog.3gstdy.com/wp-content/themes/twentyten/images/headers/path.jpg") ;
//Get pictures from the Internet
image1 .setImageBitmap(bitmap); //Set Bitmap
}
/**
* Load local pictures
*
http://bbs.3gstdy.com
*
@param url
*
@return
*/
public static Bitmap getLoacalBitmap(String url) {
try {
FileInputStream fis
= new FileInputStream(url);
return BitmapFactory.decodeStream(fis);
}
catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
}
/**
* Get pictures from the server
*
http://bbs.3gstdy.com
*
@param url
*
@return
*/
public static Bitmap getHttpBitmap(String url) {
URL myFileUrl
= null;
Bitmap bitmap
= null;
try {
Log.d(TAG, url);
myFileUrl
= new URL(url);
}
catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn
= (HttpURLConnection) myFileUrl.openConnection();
conn.setConnectTimeout(
0);
conn.setDoInput(
true);
conn.connect();
InputStream is
= conn.getInputStream();
bitmap
= BitmapFactory.decodeStream(is);
is.close();
}
catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.myimage);
ImageView image1
= (ImageView) findViewById(R.myImage.image);
//Bitmap bitmap = getLoacalBitmap("/aa/aa.jpg "); //Get pictures from local
Bitmap bitmap =
getHttpBitmap(
"http://blog.3gstdy.com/wp-content/themes/twentyten/images/headers/path.jpg") ;
//Get pictures from the Internet
image1 .setImageBitmap(bitmap); //Set Bitmap
}
/**
* Load local pictures
*
http://bbs.3gstdy.com
*
@param url
*
@return
*/
public static Bitmap getLoacalBitmap(String url) {
try {
FileInputStream fis
= new FileInputStream(url);
return BitmapFactory.decodeStream(fis);
}
catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
}
/**
* Get pictures from the server
*
http://bbs.3gstdy.com
*
@param url
*
@return
*/
public static Bitmap getHttpBitmap(String url) {
URL myFileUrl
= null;
Bitmap bitmap
= null;
try {
Log.d(TAG, url);
myFileUrl
= new URL(url);
}
catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn
= (HttpURLConnection) myFileUrl.openConnection();
conn.setConnectTimeout(
0);
conn.setDoInput(
true);
conn.connect();
InputStream is
= conn.getInputStream();
bitmap
= BitmapFactory.decodeStream(is);
is.close();
}
catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3570 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.