Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- JavaScript
- 오버로딩
- Graphic
- 에러페이지
- mybatis
- HTML
- 예외처리
- 전화걸기
- 안드로이드
- oracle
- 메소드
- 이클립스
- 어노테이션
- 국제화
- Eclips
- Menu
- JSP
- 기본
- 메서드
- OGNL
- Java
- 생성자
- paint
- 클래스
- 배열
- struts2
- AWT
- layout
- Spring
- Android
Archives
- Today
- Total
note
Access Web Image 본문
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/do_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go!" />
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Press button for action" />
<ImageView
android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
</LinearLayout>
package kr.android.webimage;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.URL;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class AccessWebImage extends Activity {
private static final String TAG="AccessWebImage";
TextView textView;
ImageView imageView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView)findViewById(R.id.text);
imageView = (ImageView)findViewById(R.id.ImageView01);
Button goButton =(Button)findViewById(R.id.do_action);
goButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try{
URL Text = new URL("http://postfiles9.naver.net/20110412_24/jms8641_13025950287563LdPD_JPEG/%BE%C6%C0%CC%C0%AF1.JPG?type=w1");
Bitmap img = getRemoteImage(Text);
imageView.setImageBitmap(img);
}catch(Exception e){
Log.e(TAG, "Erro in network call",e);
}
}
});
}
private Bitmap getRemoteImage(URL url){
Bitmap bitmap = null;
try{
//지정한 URL을 통해서 InputStream(URL의 이미지 정보) 생성
BufferedInputStream bis=
new BufferedInputStream(url.openStream());
//InputStream -> Bitmap
bitmap=BitmapFactory.decodeStream(bis);
//닫기
bis.close();
}catch(IOException e){
e.printStackTrace();
}
return bitmap;
}
}
'Android > 기본' 카테고리의 다른 글
| SQLite (0) | 2012.01.13 |
|---|---|
| SD CARD (SD 카드에 저장하기) (0) | 2012.01.13 |
| Read JSON (0) | 2012.01.13 |
| XML Resource (0) | 2012.01.13 |
| StaticFile (0) | 2012.01.12 |