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
- 오버로딩
- 국제화
- AWT
- layout
- 배열
- oracle
- 예외처리
- 클래스
- 메소드
- paint
- OGNL
- Graphic
- Android
- 전화걸기
- Java
- Eclips
- struts2
- JSP
- 메서드
- 이클립스
- 기본
- mybatis
- JavaScript
- 어노테이션
- 안드로이드
- Spring
- HTML
- Menu
- 에러페이지
- 생성자
Archives
- Today
- Total
note
Android FileSearch Gallery(사진선택) 본문
ㅁㅁ
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/photo" android:visibility="gone" android:layout_weight="1" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/text" android:visibility="gone" android:layout_weight="0"/> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/button01" android:text="사진 선택" android:layout_weight="0" /> </LinearLayout>
main activity
package dr.android.file.search;
import android.app.Activity;
import android.os.Bundle;
import java.io.File;
import java.io.IOException;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore.Images;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class FileSearchbyGallery extends Activity implements OnClickListener {
ImageView photo;
Button button01;
TextView text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
photo = (ImageView) findViewById(R.id.photo);
text = (TextView) findViewById(R.id.text);
button01 = (Button) findViewById(R.id.button01);
button01.setOnClickListener(this);
}
public void onClick(View v) {
// 갤러리를 호출해서 휴대폰에 저장된 이미지를 읽어들임
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");// image/jpg, image/png
startActivityForResult(intent, 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data != null) {
try {
Uri uri = data.getData();
// 이미지 정보 추출 및 표시
text.setText("========이미지 정보===\n");
text.append("URI : " + uri.toString() + "\n");
text.append("Last Path Segment : " + uri.getLastPathSegment()
+ "\n");
//컨텐트 프로바이더로 구성된 정보를 DB로 부터 읽어옴
Cursor c = getContentResolver().query(
Images.Media.EXTERNAL_CONTENT_URI, null,
Images.Media._ID + "=?",
new String[] { uri.getLastPathSegment() }, null);
if (c.moveToFirst()) {
//getColumnIndexOrThrow : 컬럼의 인덱스 반환
String imageFile = c.getString(c
.getColumnIndexOrThrow(Images.Media.DATA));
File f = new File(imageFile);
text.append("원본 이미지 경로 : " + imageFile + "\n");
text.append("이미지 용량 : " + f.length() + "\n");
}
text.setVisibility(View.VISIBLE);
// ImageView 이미지 보여주기
//컨텐트 프로바이더로 구성된 정보를 URI를 통해 읽어옴
Bitmap image = Images.Media
.getBitmap(getContentResolver(), uri);
text.append("크기 : " + image.getWidth() + "*"
+ image.getHeight() + "\n");
photo.setImageBitmap(image);
photo.setVisibility(View.VISIBLE);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
'Android > 기본' 카테고리의 다른 글
Android Audio사용 (음악 재생) (0) | 2012.02.01 |
---|---|
Android Constants Provider (0) | 2012.02.01 |
Android Animaiton 으로 효과 (3) | 2012.02.01 |
Android Paint로 그림그리기 (0) | 2012.02.01 |
Android Preferences 읽고 쓰기(환경설정) (0) | 2012.02.01 |