01장

Similar documents
03장

50_1953.pdf

( )부록

1부

2) 활동하기 활동개요 활동과정 [ 예제 10-1]main.xml 1 <LinearLayout xmlns:android=" 2 xmlns:tools="

2 Application Name: Day10_yhg <LinearLayout android:layout_weight="3" > /> an

[ 그림 8-1] XML 을이용한옵션메뉴설정방법 <menu> <item 항목ID" android:title=" 항목제목 "/> </menu> public boolean oncreateoptionsmenu(menu menu) { getme

[ 그림 7-1] 프로젝트 res 폴더 이미지뷰 [ 예제 7-1] 이미지뷰 1 <LinearLayout 2 ~~~~ 중간생략 ~~~~ 3 android:orientation="vertical" > 4 <ImageView

13ÀåÃß°¡ºÐ

9 차시고급위젯다루기 1 학습목표 날짜 / 시간과관련된위젯을배운다. 웹뷰를사용하여간단한웹브라우저기능을구현한다. 매니패스트파일의설정법을배운다. 2 확인해볼까? 3 날짜 / 시간위젯 1) 활동하기 활동개요

리니어레이아웃 - 2 -

안드로이드기본 11 차시어댑터뷰 1 학습목표 어댑터뷰가무엇인지알수있다. 리스트뷰와스피너를사용하여데이터를출력할수있다. 2 확인해볼까? 3 어댑터뷰 1) 학습하기 어댑터뷰 - 1 -

OpenCV와 함께하는 컴퓨터 비전 프로그래밍 캠프

학습목표 선언하여디자인을하는방법을이해하고, 실행할수있다. 시작화면을만드는방법과대체리소스를사용하는방법을이해하고실행할수있다. About 과같은상자를구현하고, 테마를적용하는법을이해하고실행할수있다.

어댑터뷰

슬라이드 1

01 [ 일기장 ] 애플리케이션프로젝트작성 - [MyDiary] 앱 Mobile Apps >> [MyDiary] 앱프로젝트구조설계 일기장애플리케이션인 [MyDiary] 앱은메인화면과일기장의내용을작성하는화면으로이루어져있다. 화면이 2개라는것은액티비티가 2개이고액티비티에대

슬라이드 1

PowerPoint 프레젠테이션

SECTION 01 _ 액션바 (ActionBar) 405 액션바만들기 참고프로젝트 ActionBarDemoA1 간단히액션바를만들고이액션바가 WVGA(800*480) 과 WXGA(1280*800) 에서어떻게보이는지확인해보도록하겠다. 액션바를만든다는표현을했지만액션바는타이

TipssoftAppActivity.java // 기본소스파일 main.xml // 배치와구성에관련된리소스파일 string.xml // 프로그램에서사용할문자열에관련된리소스파일 컴파일을하고나면 r.java 라는소스파일이하나추가되는데이파일은리소스파일을소스파일에서이용할수있도

오핀 (OFIN) SDK Guide Fintech Mobile SDK Guide - Android V 1.0 OPPFLIB 1

안드로이드2_14

헬로, 안드로이드 13 주차 SQL 활용하기 (2) 강대기동서대학교컴퓨터정보공학부

REMON Android SDK GUIDE (SDK Version 1.4.1) 1 / 25

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

학습목표 메뉴를추가하는방법을이해하고실습할수있다. 프로그램의기본설정 (settings) 을정의하는방법을알고실습할수있다. 대화상자를여는방법을알고실습할수있다. 로그메시지로디버깅하는방법을이해한다. 디버거로디버깅하는방법을이해한다.

rmi_박준용_final.PDF

안드로이드애플리케이션과통합하는데는자바가편하므로대표적인두가지라이브러리를비교해보자. 자바 ID3 태그라이브러리 jaudiotagger ID3v1, ID3v1.1, Lyrics3v1, Mp3, Mp4 (Mp4 오디오, M4a 지원범위 Lyrics3v2, ID3v2.2, ID

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

(Microsoft PowerPoint - Ch06.ppt [\310\243\310\257 \270\360\265\345])

PowerPoint 프레젠테이션

슬라이드 1

// 화면을터치하였을때해야할작업구현 case MotionEvent.ACTION_MOVE: // 화면을드래그하였때 // 화면을드래그하였을때해야할작업구현 case MotionEvent.ACTION_UP: // 화면에서터치가사라질때 // 화면에서터치가사라질때해야할자업구현 c

SQLite v 소개 ü SQLite 라이브러리를통해완전한관계형데이터베이스 (RDBMS) 기능제공 ü 오픈소스 ü 표준준수 ü 경량 ü 단일계층 2

09-interface.key

12-file.key

슬라이드 1

위젯과레이아웃위젯은 View 클래스를상속해화면디스플레이와이벤트처리를할수있도록구현된스크린구성의최소단위를말한다. android.widget 패키지에는여러유형의위젯들이포함되어있다. TextView, ImageView, Button, ImageButton 등은가장간단한위젯들이

#한국사문제7회4급

rosaec_workshop_talk

JMF3_심빈구.PDF

구글안드로이드프로그래밍액티비티, 인텐트수신자, 그리고서비스 안드로이드애플리케이션의구성요소에는액티비티, 인텐트수신자, 서비스, 컨텐트제공자가있다. 이번호에서는사용자인터페이스를위한액티비티와백그라운드서비스를위한인텐트수신자, 그리고서비스의라이프사이클과활용법에대해살펴보도록하자.

02 C h a p t e r Java

학습목표 SQLite 가뭔지알고, 이를사용할줄안다. SQL 의기본적인사용법들을안다. SQLite 을이용해기본적인데이터베이스응용프로그램을작성할수있다. 행을추가하는기본적인데이터베이스응용프로그램을작성할수있다. 쿼리를실행하는기본적인데이터베이스응용프로그램을작성할수있다. 쿼리결과

신림프로그래머_클린코드.key

Microsoft PowerPoint - 4주차_Android_UI구현.ppt [호환 모드]

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

자바GUI실전프로그래밍2_장대원.PDF

전자공학설계실험 A 보고서 화 6A ~ 9B 박종태교수님 제출기한 ( 화 ) Android I.S 작업환경 Eclipse_Juno ver. 전자공학부 이상엽전자공학부 오윤재전자공학부

비긴쿡-자바 00앞부속

이것은리스트뷰의 setadapter 메소드에잘표현되어있습니다. setadapter 는리스트뷰에사용할데이터객체를넘겨주는메소드입니다. 일반적으로생각한다면 ArrayAdapter 객체를생성하여사용할데이터를저장할것이고데이터가저장된 ArrayAdapter 객체를 setadapt

JMF2_심빈구.PDF

Daum 카페

슬라이드 1

Contents v 학습목표 뷰와레이아웃에대해이해하고, 레이아웃을활용, 관리하는여러가지기법들에대하여알아본다. v 내용 뷰 (View) 리니어레이아웃 (Linear Layout)

¾Èµå·ÎÀÌµå ³¹Àå-Åë.PDF

슬라이드 1

04장

헬로, 안드로이드 11 주차 위치파악하기와감지하기 강대기동서대학교컴퓨터정보공학부

1. 개요 - 계획서 프로젝트개요프로그램명 : 닥터 119 제작배경애완견을키우는사람들이부득이하게병원에가지못할경우에이앱을통해서자가진단을통해상태의심각성을알수있게되고또가까운동물병원으로갈수있는지도와전화번호를제공한다. 그리고애견다이어리기능을통해애견의성장과정과추억들을저

PowerPoint 프레젠테이션

@OneToOne(cascade = = "addr_id") private Addr addr; public Emp(String ename, Addr addr) { this.ename = ename; this.a

I T C o t e n s P r o v i d e r h t t p : / / w w w. h a n b i t b o o k. c o. k r

Microsoft PowerPoint - 04-UDP Programming.ppt

Spring Boot/JDBC JdbcTemplate/CRUD 예제

13주-14주proc.PDF

untitled

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

XML Parser

NoSQL

3장

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

untitled

12 주차 인텐트

Microsoft PowerPoint - DoItAndroid_PART02_01_기본위젯과레이아웃_Rev.1.0 [호환 모드]

Activity

Chap 8 호스트시스템개발환경구성및 안드로이드개발환경구축

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형

12Àå PDF

DocsPin_Korean.pages

쉽게 풀어쓴 C 프로그래밊

슬라이드 1

1. 화면전환 [ 그림 1] 화면전홖에대한상태도 [ 그림 1] 은게임전반적이화면전홖에대한상태도입니다. 이에대한설명은아래와같습니다. Intro: 게임이시작될때보여주는화면. 화면이보여지고난뒤 2초후면 Main으로이동합니다. 실제게임에서는필요한데이터등을로딩하는동안보여주는형식

자바-11장N'1-502

자바 프로그래밍

MasoJava4_Dongbin.PDF

슬라이드 1

학습목표 게임이나프로그램에옵션을추가하는방법을알아본다. 이전의프로그램을계속하기위해상태를저장하는방법을알아본다. 게임에서현재의실행위치를저장하는방법에대해알아본다. 내부의파일시스템을읽고쓰는방법에대해알아본다. SD 카드에접근하는방법에대해알아본다. 여러 UI 위젯들에대해알아본다.

iOS4_13

3ÆÄÆ®-14

¾Ë·¹¸£±âÁöħ¼�1-ÃÖÁ¾

01....b

2007백서-001-특집

(291)본문7

00목차

01-OOPConcepts(2).PDF

<4D F736F F D20284B B8F0B9D9C0CF20BED6C7C3B8AEC4C9C0CCBCC720C4DCC5D9C3F720C1A2B1D9BCBA2020C1F6C4A720322E302E646F6378>

FileMaker ODBC and JDBC Guide

교육2 ? 그림

Transcription:

CHAPTER1 Camera (MediaStore) EXIF 1

2 CHAPTER 1 SDK (intent) Camera Camera Camera Android Manifest xml Camera Camera <intent-filter> <action android:name= android.media.action.image_capture /> <category android:name= android.intent.category.default /> </intent-filter> Camera

3 Intent i = new Intent( android.media.action.image_capture ); MediaStore ACTION_IMAGE_CAPTURE Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startactivity(i); Camera 1 1 Camera

4 CHAPTER 1 Camera startactivity startactivityforresult startactivityforresult Camera package com.apress.proandroidmedia.ch1.cameraintent; import android.app.activity; import android.content.intent; import android.graphics.bitmap; import android.os.bundle; import android.widget.imageview; public class CameraIntent extends Activity final static int CAMERA_RESULT = 0; ImageView imv; @Override public void oncreate(bundle savedinstancestate) super.oncreate(savedinstancestate); setcontentview(r.layout.main); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startactivityforresult(i, CAMERA_RESULT); protected void onactivityresult(int requestcode, int resultcode, Intent intent) super.onactivityresult(requestcode, resultcode, intent); if (resultcode == RESULT_OK) Bundle extras = intent.getextras(); Bitmap bmp = (Bitmap) extras.get( data );

5 imv = (ImageView) findviewbyid(r.id.returnedimageview); imv.setimagebitmap(bmp); layout/main xml <?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 > <ImageView android:id= @+id/returnedimageview android:layout_width= wrap_content ë android:layout_height= wrap_content ></ImageView> </LinearLayout> AndroidManifest xml <?xml version= 1.0 encoding= utf-8?> <manifest xmlns:android= http://schemas.android.com/apk/res/android android:versioncode= 1 android:versionname= 1.0 package= com.apress.proandroidmedia.ch1.cameraintent > <application android:icon= @drawable/icon android:label= @string/app_name > <activity android:name=.cameraintent android:label= @string/app_name > <intent-filter> <action android:name= android.intent.action.main /> <category android:name= android.intent.category.launcher /> </intent-filter> </activity> </application> <uses-sdk android:minsdkversion= 4 /> </manifest>

6 CHAPTER 1 extra( ) Camera onactivityresult extra data Bitmap (generic) // extra Bundle extras = intent.getextras(); // extra Bitmap bmp = (Bitmap) extras.get( data ); XML (layout/main xml) ImageView ImageView View ImageView id ReturnedImageView ImageView Activity findviewbyid XML setcontentview id ImageView XML <ImageView android:id= @+id/returnedimageview android:layout_width= wrap_content ë android:layout_height= wrap_content ></ImageView> ImageView Camera Bitmap imv = (ImageView) findviewbyid(r.id.returnedimageview);imv.setimagebitmap(bmp); ( 121 162 ) Camera

7 Camera 1 2 1 5 Camera extra extra MediaStore EXTRA_OUTPUT (extra ) Camera URI

8 CHAPTER 1 Camera SD myfavoritepicture jpg String imagefilepath = Environment.getExternalStorageDirectory().getAbsolutePath() ë + /myfavoritepicture.jpg ; File imagefile = new File(imageFilePath); Uri imagefileuri = Uri.fromFile(imageFile); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); i.putextra(android.provider.mediastore.extra_output, imagefileuri); startactivityforresult(i, CAMERA_RESULT); Note imagefileuri = Uri.parse( file:///sdcard/myfavoritepicture.jpg ); HTC G1( ) 320 2048x1536 32 13MB BitmapFactory BitmapFactory BitmapFactory Options Bitmap

9 BitmapFactory BitmapFactory Options insamplesize Bitmap insamplesize 8 8 1 BitmapFactory.Options bmpfactoryoptions = new BitmapFactory.Options(); bmpfactoryoptions.insamplesize = 8; Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpfactoryoptions); imv.setimagebitmap(bmp); 100 Display currentdisplay = getwindowmanager().getdefaultdisplay(); int dw = currentdisplay.getwidth(); int dh = currentdisplay.getheight(); BitmapFactory Options injustdecodebounds true BitmapFactory BitmapFactory Options BitmapFactory BitmapFactory Options outheight BitmapFactory Options outwidth

10 CHAPTER 1 //. BitmapFactory.Options bmpfactoryoptions = new BitmapFactory.Options(); bmpfactoryoptions.injustdecodebounds = true; Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpfactoryoptions); int heightratio = (int)math.ceil(bmpfactoryoptions.outheight/(float)dh); int widthratio = (int)math.ceil(bmpfactoryoptions.outwidth/(float)dw); Log.v( HEIGHTRATIO, +heightratio); Log.v( WIDTHRATIO, +widthratio); ( ) ( ) BitmapFactory Options insamplesize //,. if (heightratio > 1 && widthratio > 1) if (heightratio > widthratio) //. bmpfactoryoptions.insamplesize = heightratio; else //. bmpfactoryoptions.insamplesize = widthratio; //. bmpfactoryoptions.injustdecodebounds = false; bmp = BitmapFactory.decodeFile(imageFilePath, bmpfactoryoptions);

11 1 3 package com.apress.proandroidmedia.ch1.sizedcameraintent; import java.io.file; import android.app.activity; import android.content.intent; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.net.uri; import android.os.bundle; import android.os.environment; import android.util.log; import android.view.display; import android.widget.imageview; public class SizedCameraIntent extends Activity final static int CAMERA_RESULT = 0; ImageView imv; String imagefilepath; @Override public void oncreate(bundle savedinstancestate) super.oncreate(savedinstancestate); setcontentview(r.layout.main); imagefilepath = Environment.getExternalStorageDirectory().getAbsolutePath() + /myfavoritepicture.jpg ; File imagefile = new File(imageFilePath); Uri imagefileuri = Uri.fromFile(imageFile); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); i.putextra(android.provider.mediastore.extra_output, imagefileuri); startactivityforresult(i, CAMERA_RESULT); protected void onactivityresult(int requestcode, int resultcode, Intent intent)

12 CHAPTER 1 super.onactivityresult(requestcode, resultcode, intent); if (resultcode == RESULT_OK) // ImageView. imv = (ImageView) findviewbyid(r.id.returnedimageview); Display currentdisplay = getwindowmanager().getdefaultdisplay(); int dw = currentdisplay.getwidth(); int dh = currentdisplay.getheight(); //. BitmapFactory.Options bmpfactoryoptions = new BitmapFactory.Options(); bmpfactoryoptions.injustdecodebounds = true; Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpfactoryoptions); int heightratio = (int) Math.ceil(bmpFactoryOptions.outHeight / (float) dh); int widthratio = (int) Math.ceil(bmpFactoryOptions.outWidth / (float) dw); Log.v( HEIGHTRATIO, + heightratio); Log.v( WIDTHRATIO, + widthratio); // 1,. if (heightratio > 1 && widthratio > 1) if (heightratio > widthratio) //. bmpfactoryoptions.insamplesize = heightratio; else //. bmpfactoryoptions.insamplesize = widthratio; //. bmpfactoryoptions.injustdecodebounds = false; bmp = BitmapFactory.decodeFile(imageFilePath, bmpfactoryoptions); //. imv.setimagebitmap(bmp);

13 layout/main xml <?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 > <ImageView android:id= @+id/returnedimageview android:layout_width= wrap_content ë android:layout_height= wrap_content ></ImageView> </LinearLayout>

14 CHAPTER 1 ( ) MediaStore MediaStore MediaStore SizedCameraIntent MediaStore SD MediaStore MediaStore URI MediaStore insert URI android provider MediaStore Images Media EXTERNAL_CONTENT_ URI SD INTERNAL_ CONTENT_URI EXTERNAL_CONTENT_URI

15 (insert) URI URI CameraActivity Camera extra Uri imagefileuri = getcontentresolver().insert( Media.EXTERNAL_CONTENT_URI, new ContentValues()); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); i.putextra(android.provider.mediastore.extra_output, imagefileuri); startactivityforresult(i, CAMERA_RESULT); ContentValues ContentValues ContentValues put ContentValues android provider MediaStore Images Media ( android provider MediaStore MediaColumns Media ) //. ContentValues contentvalues = new ContentValues(3); contentvalues.put(media.display_name, This is a test title ); contentvalues.put(media.description, This is a test description ); contentvalues.put(media.mime_type, image/jpeg ); //. // insert() URI. Uri imagefileuri = getcontentresolver().insert(media.external_content_uri, contentvalues); URI Camera

16 CHAPTER 1 URI Log content://media/external/images/media/16 URL http content URI content ( MediaStore) URI BitmapFactory InputStream BitmapFactory Bitmap bmp = BitmapFactory.decodeStream( ë getcontentresolver().openinputstream(imagefileuri), null, bmpfactoryoptions); MediaStore update update insert update URI //. ContentValues contentvalues = new ContentValues(3); contentvalues.put(media.display_name, This is a test title ); contentvalues.put(media.description, This is a test description ); getcontentresolver().update(imagefileuri,contentvalues,null,null);

17 MediaStore UI package com.apress.proandroidmedia.ch1.mediastorecameraintent; import java.io.filenotfoundexception; import android.app.activity; import android.content.intent; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.net.uri; import android.os.bundle; import android.util.log; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; import android.widget.imageview; import android.widget.textview; import android.widget.toast; import android.provider.mediastore.images.media; import android.content.contentvalues; public class MediaStoreCameraIntent extends Activity final static int CAMERA_RESULT = 0; Uri imagefileuri; // res/layout/main.xml ImageView returnedimageview; Button takepicturebutton; Button savedatabutton; TextView titletextview;

18 CHAPTER 1 TextView descriptiontextview; EditText titleedittext; EditText descriptionedittext; layout/main xml @Override public void oncreate(bundle savedinstancestate) super.oncreate(savedinstancestate); // res/layout/main.xml. setcontentview(r.layout.main); // UI. returnedimageview = (ImageView) findviewbyid(r.id.returnedimageview); takepicturebutton = (Button) findviewbyid(r.id.takepicturebutton); savedatabutton = (Button) findviewbyid(r.id.savedatabutton); titletextview = (TextView) findviewbyid(r.id.titletextview); descriptiontextview = (TextView) findviewbyid(r.id.descriptiontextview); titleedittext = (EditText) findviewbyid(r.id.titleedittext); descriptionedittext = (EditText) findviewbyid(r.id.descriptionedittext); oncreate setcontentview findviewbyid // takepicturebutton. // View.GONE. returnedimageview.setvisibility(view.gone); savedatabutton.setvisibility(view.gone); titletextview.setvisibility(view.gone); descriptiontextview.setvisibility(view.gone); titleedittext.setvisibility(view.gone); descriptionedittext.setvisibility(view.gone);

19 View GONE setvisibility View INVISIBLE // takepicturebutton takepicturebutton.setonclicklistener(new OnClickListener() public void onclick(view v) //. // URI. imagefileuri = getcontentresolver().insert(media.external_content_uri, ë new ContentValues()); ); // Camera. Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); i.putextra(android.provider.mediastore.extra_output, imagefileuri); startactivityforresult(i, CAMERA_RESULT); takepicturebutton OnClickListener startactivityforresult oncreate savedatabutton.setonclicklistener(new OnClickListener() public void onclick(view v) // MediaStore. ContentValues contentvalues = new ContentValues(3); contentvalues.put(media.display_name, titleedittext.gettext().tostring()); contentvalues.put(media.description, descriptionedittext.gettext().tostring()); getcontentresolver().update(imagefileuri,contentvalues,null,null); //. Toast bread = Toast.makeText(MediaStoreCameraIntent.this, Record ë Updated, Toast.LENGTH_SHORT);

20 CHAPTER 1 bread.show(); // takepicturebutton. // UI. takepicturebutton.setvisibility(view.visible); ); returnedimageview.setvisibility(view.gone); savedatabutton.setvisibility(view.gone); titletextview.setvisibility(view.gone); descriptiontextview.setvisibility(view.gone); titleedittext.setvisibility(view.gone); descriptionedittext.setvisibility(view.gone); savedatabutton OnClickListener Camera EditText ContentValues MediaStore protected void onactivityresult(int requestcode, int resultcode, Intent intent) super.onactivityresult(requestcode, resultcode, intent); if (resultcode == RESULT_OK) // Camera. // takepicturebutton. takepicturebutton.setvisibility(view.gone); // UI. savedatabutton.setvisibility(view.visible); returnedimageview.setvisibility(view.visible); titletextview.setvisibility(view.visible); descriptiontextview.setvisibility(view.visible); titleedittext.setvisibility(view.visible);

21 descriptionedittext.setvisibility(view.visible); //. int dw = 200; // 200 int dh = 200; // 200 try //. BitmapFactory.Options bmpfactoryoptions = new BitmapFactory.Options(); bmpfactoryoptions.injustdecodebounds = true; Bitmap bmp = BitmapFactory.decodeStream(getContentResolver(). ë openinputstream(imagefileuri), null, bmpfactoryoptions); int heightratio = (int)math.ceil(bmpfactoryoptions.outheight/(float)dh); int widthratio = (int)math.ceil(bmpfactoryoptions.outwidth/(float)dw); Log.v( HEIGHTRATIO, +heightratio); Log.v( WIDTHRATIO, +widthratio); // 1,. if (heightratio > 1 && widthratio > 1) if (heightratio > widthratio) //. bmpfactoryoptions.insamplesize = heightratio; else //. bmpfactoryoptions.insamplesize = widthratio; //. bmpfactoryoptions.injustdecodebounds = false; bmp = BitmapFactory.decodeStream(getContentResolver(). ë openinputstream(imagefileuri), null, bmpfactoryoptions); //. returnedimageview.setimagebitmap(bmp);

22 CHAPTER 1 catch (FileNotFoundException e) Log.v( ERROR,e.toString()); XML main xml <?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 > <ImageView android:id= @+id/returnedimageview android:layout_width= wrap_content ë android:layout_height= wrap_content ></ImageView> <TextView android:layout_width= wrap_content android:layout_height= wrap_content ë android:text= Title: android:id= @+id/titletextview ></TextView> <EditText android:layout_height= wrap_content android:id= @+id/titleedittext ë android:layout_width= fill_parent ></EditText> <TextView android:layout_width= wrap_content android:layout_height= wrap_content ë android:text= Description android:id= @+id/descriptiontextview ></TextView> <EditText android:layout_height= wrap_content android:layout_width= fill_parent ë android:id= @+id/descriptionedittext ></EditText> <Button android:layout_width= wrap_content android:layout_height= wrap_content ë android:id= @+id/takepicturebutton android:text= Take Picture ></Button> <Button android:layout_width= wrap_content android:layout_height= wrap_content ë android:id= @+id/savedatabutton android:text= Save Data ></Button> </LinearLayout> onactivityresult Camera Bitmap

23 ( MediaStore) MediaStore MediaStore URI Media.EXTERNAL_CONTENT_URI MediaStore Cursor MediaStore MediaStore Images Media String[] columns = Media.DATA, Media._ID, Media.TITLE, Media.DISPLAY_NAME ; managedquery URI WHERE WHERE ORDER BY onehourago 1970 1 1 System currentimemillis() 1970 1 1 1 000 60 60

24 CHAPTER 1 long onehourago = System.currentTimeMillis()/1000 - (60 * 60) WHERE String[] wherevalues = +onehourago; String[] columns = Media.DATA, Media._ID, Media.TITLE, Media.DISPLAY_NAME, Media.DATE_ADDED ; WHERE (?) ORDER BY cursor = managedquery(media.external_content_uri, columns, Media.DATE_ADDED + >?,ë wherevalues, Media.DATE_ADDED + ASC ); null Cursor cursor = managedquery(media.external_content_uri, columns, null, null, null); displaycolumnindex = cursor.getcolumnindexorthrow(mediastore.images.media.data); movetofirst Cursor

25 getstring getint if (cursor.movetofirst()) String displayname = cursor.getstring(displaycolumnindex); MediaStore package com.apress.proandroidmedia.ch1.mediastoregallery; import android.app.activity; import android.database.cursor; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.os.bundle; import android.provider.mediastore; import android.provider.mediastore.images.media; import android.util.log; import android.view.view; import android.view.view.onclicklistener; import android.widget.imagebutton; import android.widget.textview; public class MediaStoreGallery extends Activity public final static int DISPLAYWIDTH = 200; public final static int DISPLAYHEIGHT = 200;

26 CHAPTER 1 TextView titletextview; ImageButton imagebutton; ImageView ImageButton Button ( ) ImageView( ) Cursor cursor; Bitmap bmp; String imagefilepath; int filecolumn; int titlecolumn; int displaycolumn; @Override public void oncreate(bundle savedinstancestate) super.oncreate(savedinstancestate); setcontentview(r.layout.main); titletextview = (TextView) this.findviewbyid(r.id.titletextview); imagebutton = (ImageButton) this.findviewbyid(r.id.imagebutton); managedquery String[] columns = Media.DATA, Media._ID, Media.TITLE, Media.DISPLAY_NAME ; cursor = managedquery(media.external_content_uri, columns, null, null, null); Cursor Media DATA MediaStore Images Media DATA android provider MediaStore Images Media import Media DATA filecolumn = cursor.getcolumnindexorthrow(mediastore.images.media.data); titlecolumn = cursor.getcolumnindexorthrow(mediastore.images.media.title); displaycolumn = cursor.getcolumnindexorthrow(mediastore.images.media.display_name);

27 Cursor movetofirst if (cursor.movetofirst()) // titletextview.settext(cursor.getstring(titlecolumn)); titletextview.settext(cursor.getstring(displaycolumn)); imagefilepath = cursor.getstring(filecolumn); bmp = getbitmap(imagefilepath); //. imagebutton.setimagebitmap(bmp); ImageButton OnClickListener OnClickListener Cursor MoveToNext imagebutton.setonclicklistener(new OnClickListener() public void onclick(view v) if (cursor.movetonext()) // titletextview.settext(cursor.getstring(titlecolumn)); titletextview.settext(cursor.getstring(displaycolumn)); ); imagefilepath = cursor.getstring(filecolumn); bmp = getbitmap(imagefilepath); imagebutton.setimagebitmap(bmp); getbitmap

28 CHAPTER 1 private Bitmap getbitmap(string imagefilepath) //. BitmapFactory.Options bmpfactoryoptions = new BitmapFactory.Options(); bmpfactoryoptions.injustdecodebounds = true; Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpfactoryoptions); int heightratio = (int) Math.ceil(bmpFactoryOptions.outHeight ë / (float) DISPLAYHEIGHT); int widthratio = (int) Math.ceil(bmpFactoryOptions.outWidth ë / (float) DISPLAYWIDTH); Log.v( HEIGHTRATIO, + heightratio); Log.v( WIDTHRATIO, + widthratio); // 1,. if (heightratio > 1 && widthratio > 1) if (heightratio > widthratio) //. bmpfactoryoptions.insamplesize = heightratio; else //. bmpfactoryoptions.insamplesize = widthratio; //. bmpfactoryoptions.injustdecodebounds = false; bmp = BitmapFactory.decodeFile(imageFilePath, bmpfactoryoptions); return bmp; XML res/layout/main xml <?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

29 android:layout_height= fill_parent > <ImageButton android:layout_width= wrap_content android:layout_height= wrap_content ë android:id= @+id/imagebutton ></ImageButton> <TextView android:layout_width= fill_parent android:layout_height= wrap_content android:id= @+id/titletextview android:text= Image Title /> </LinearLayout> EXIF EXIF EXIF SD EXIF iphoto EXIF EXIF ExposureTime ShutterSpeedValue : : : :

30 CHAPTER 1 EXIF ExifInterface ExifInterface EXIF ExifInterface ei = new ExifInterface(imageFilePath); String imagedescription = ei.getattribute( ImageDescription ); if (imagedescription!= null) Log.v( EXIF, imagedescription); ExifInterface EXIF ExifInterface ei = new ExifInterface(imageFilePath); ei.setattribute( ImageDescription, Something New ); ExifInterface Camera EXIF 2010 4 2 3 www cipa jp/english/ hyoujunka/kikaku/pdf/dc 008 2010_E pdf Camera Camera

31 BitmapFactory MediaStore EXIF EXIF EXIF!