03장

Similar documents
01장

( )부록

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

50_1953.pdf

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

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

13ÀåÃß°¡ºÐ

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

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

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

리니어레이아웃 - 2 -

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

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

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

슬라이드 1

PowerPoint 프레젠테이션

어댑터뷰

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

안드로이드2_14

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

슬라이드 1

PowerPoint 프레젠테이션

슬라이드 1

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

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

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

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

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

비긴쿡-자바 00앞부속

02 C h a p t e r Java

PowerPoint 프레젠테이션

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

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

12-file.key

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

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

rmi_박준용_final.PDF

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

09-interface.key

5장.key

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

untitled

Microsoft PowerPoint - 04-UDP Programming.ppt

01-OOPConcepts(2).PDF

슬라이드 1

04장

JMF3_심빈구.PDF

PowerPoint 프레젠테이션

DWCOM15/17_manual

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

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

SKT UCC DRM

제8장 자바 GUI 프로그래밍 II

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

* Factory class for query and DML clause creation * tiwe * */ public class JPAQueryFactory implements JPQLQueryFactory private f

1부

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

untitled

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

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

01....b

00목차

(291)본문7

2007백서-001-특집

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

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

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

ch09

MasoJava4_Dongbin.PDF

rosaec_workshop_talk

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

3장

Microsoft PowerPoint - Java7.pptx

자바 프로그래밍

Modern Javascript

JMF2_심빈구.PDF

LCD Display

Microsoft PowerPoint - lec2.ppt

안드로이드테스트앱을이용한난독화라이브러리파일동적분석 - 중요정보가라이브러리파일내부에 암호화되어있는악성앱동적분석 코드분석팀송지훤 본보고서의전부나일부를인용시, 반드시 [ 자료 : 한국인터넷진흥원 (KISA)] 를명시하

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

FileMaker ODBC and JDBC Guide

Spring Data JPA Many To Many 양방향 관계 예제

INAPP결제 API 가이드

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

초보자를 위한 C# 21일 완성

목 록( 目 錄 )

02-1기록도전( )

03-1영역형( )

1 안드로이드스튜디오설치와설정과정 Jeff Friesen JavaWorld 최근몇년동안의추세를볼때현재모바일운영체제시장은안드로이드가지배한다고해도과언이아니다. 자바기반의안드로이드운영체제는새로운디지털골드러쉬를일으켰고모바일앱에서기회를얻으려는프로그래 머들이앞다투어안드로이드로모여

K&R2 Reference Manual 번역본

歯Phone

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

PowerPoint Presentation

FileMaker ODBC and JDBC Guide

14-Servlet

07 자바의 다양한 클래스.key

1

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

Spring Boot/JDBC JdbcTemplate/CRUD 예제

Transcription:

CHAPTER3 ( ) Gallery 67

68 CHAPTER 3 Intent ACTION_PICK URI android provier MediaStore Images Media EXTERNAL_CONTENT_URI URI SD MediaStore Intent choosepictureintent = new Intent(Intent.ACTION_PICK, ë android.provider.mediastore.images.media.external_content_uri); Gallery onactivityresult URI onactivityresult(int requestcode, int resultcode, Intent intent) { super.onactivityresult(requestcode, resultcode, intent); if (resultcode == RESULT_OK) { Uri imagefileuri = intent.getdata(); package com.apress.proandroidmedia.ch3.choosepicture; 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.display;

69 import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.imageview; OnClickListener oncreate UI findviewbyid UI XML public class ChoosePicture extends Activity implements OnClickListener { ImageView chosenimageview; Button choosepicture; @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); chosenimageview = (ImageView) this.findviewbyid(r.id.chosenimageview); choosepicture = (Button) this.findviewbyid(r.id.choosepicturebutton); choosepicture.setonclicklistener(this); onclick choosepicture 3 1 Gallery Gallery 3 2

70 CHAPTER 3 public void onclick(view v) { Intent choosepictureintent = new Intent(Intent.ACTION_PICK, ë android.provider.mediastore.images.media.external_content_uri); startactivityforresult(choosepictureintent, 0);

71 Gallery onactivityresult URI protected void onactivityresult(int requestcode, int resultcode, Intent intent) { super.onactivityresult(requestcode, resultcode, intent); if (resultcode == RESULT_OK) { Uri imagefileuri = intent.getdata(); 1 dw int dh int

72 CHAPTER 3 Display currentdisplay = getwindowmanager().getdefaultdisplay(); int dw = currentdisplay.getwidth(); int dh = currentdisplay.getheight() / 2-100; 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); 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); chosenimageview.setimagebitmap(bmp); catch (FileNotFoundException e) { Log.v( ERROR, e.tostring()); XML layout/main xml

73 <?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:layout_width= fill_parent android:layout_height= wrap_content android:text= Choose Picture android:id= @+id/choosepicturebutton /> <ImageView android:layout_width= wrap_content android:layout_height= wrap_content android:id= @+id/chosenimageview ></ImageView> </LinearLayout>

74 CHAPTER 3 Bitmap Bitmap 3 3 Bitmap Bitmap Bitmap Bitmap Bitmap 1 BitmapFactory decodestream Bitmap bmp = BitmapFactory.decodeStream(getContentResolver(). ë openinputstream(imagefileuri), null, bmpfactoryoptions); Bitmap Bitmap Bitmap Bitmap Bitmap Bitmap alteredbitmap = Bitmap.createBitmap(bmp.getWidth(), ë bmp.getheight(), bmp.getconfig()); alteredbitmap Bitmap bmp ( color depth) Bitmap Config Bitmap createbitmap (mutable) Bitmap (mutable) Bitmap

75 (immutable) Bitmap Bitmap Canvas Canvas Canvas Bitmap Canvas canvas = new Canvas(alteredBitmap); Paint Paint Paint Paint paint = new Paint(); Bitmap (mutable) Bitmap Bitmap bmp = BitmapFactory.decodeStream(getContentResolver(). openinputstream(imagefileuri), null, bmpfactoryoptions); Bitmap alteredbitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getheight(), bmp.getconfig()); Canvas canvas = new Canvas(alteredBitmap); Paint paint = new Paint(); canvas.drawbitmap(bmp, 0, 0, paint); ImageView alteredimageview = (ImageView) this.findviewbyid(r.id.alteredimageview); alteredimageview.setimagebitmap(alteredbitmap);

76 CHAPTER 3 Canvas drawbitmap Paint Bitmap x y alteredbitmap Choose Picture onactivityresult bmp = BitmapFactory decodestream import alteredbitmap ImageView alteredbitmap setimagebitmap XML id AlteredImageView ImageView XML 3 4 alteredbitmap ImageView ImageView <?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:layout_width= fill_parent android:layout_height= wrap_content android:text= Choose Picture android:id= @+id/choosepicturebutton /> <ImageView android:layout_width= wrap_content android:layout_height= wrap_content ë android:id= @+id/chosenimageview ></ImageView> <ImageView android:layout_width= wrap_content android:layout_height= wrap_content ë android:id= @+id/alteredimageview ></ImageView> </LinearLayout>

77 / / API Matrix Bitmap Bitmap Bitmap

78 CHAPTER 3 (spatial transformation) / Matrix 9 Matrix Matrix Matrix (x y z) Matrix 9 1 0 0 0 1 0 0 0 1 (1 0 0) x=1x+0y+0z x x x y z (0 1 0) y y=0x+1y+0z (0 0 1) z z = 0x +0y + 1z Matrix Matrix setvalues Matrix

79 Matrix matrix = new Matrix(); matrix.setvalues(new float[] { 1, 0, 0, 0, 1, 0, 0, 0, 1 ); drawbitmap canvas.drawbitmap(bmp, matrix, paint); Matrix 1 5 3 5 x 50% x x.5 0 0 0 1 0 0 0 1 Matrix matrix = new Matrix(); matrix.setvalues(new float[] {.5f, 0, 0, 0, 1, 0, 0, 0, 1 ); canvas.drawbitmap(bmp, matrix, paint);

80 CHAPTER 3 x y Matrix matrix = new Matrix(); matrix.setvalues(new float[] { 1,.5f, 0, 0, 1, 0, 0, 0, 1 ); canvas.drawbitmap(bmp, matrix, paint);

81 3 6 x y y x 3 7 alteredbitmap = Bitmap.createBitmap(bmp.getWidth()*2,bmp.getHeight(),bmp.getConfig());

82 CHAPTER 3 Matrix Matrix (Wikipedia Transformation Matrix) http://en wikipedia org/wiki/ Transformation_matrix Matrix

83 Matrix canvas drawbitmap setrotation setrotation float (0 0) 3 8 Matrix matrix = new Matrix(); matrix.setrotate(15); canvas.drawbitmap(bmp, matrix, paint);

84 CHAPTER 3 setrotation 3 9 matrix.setrotate(15,bmp.getwidth()/2,bmp.getheight()/2); Matrix setscale setscale / float x y 3 10 setscale

85 matrix.setscale(1.5f,1); Matrix settranslate (translate) x y settranslate float x y x y x y

86 CHAPTER 3 settranslate(1.5f,-10); prescale setrotate setscale postrotate 3 11 matrix.setscale(1.5f, 1); matrix.postrotate(15,bmp.getwidth()/2,bmp.getheight()/2);

87 setscale posttranslate ( ) / 0 0 x posttranslate 3 12 matrix.setscale(-1, 1); matrix.posttranslate(bmp.getwidth(),0);

88 CHAPTER 3 y 180 3 13 matrix.setscale(1, -1); matrix.posttranslate(0, bmp.getheight());

89 Bitmap Bitmap Bitmap Matrix Canvas Paint Bitmap Bitmap createbitmap Bitmap x y Matrix Matrix matrix = new Matrix(); matrix.setrotate(15,bmp.getwidth()/2,bmp.getheight()/2); alteredbitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getwidth(), bmp.getheight(), matrix, false); alteredimageview.setimagebitmap(alteredbitmap); Bitmap(alteredBitmap) (bmp) Matrix Bitmap / Bitmap

90 CHAPTER 3 / Canvas Matrix ColorMatrix Canvas Paint

91 ColorMatrix Matrix ColorMatrix x y z Red Green Blue Alpha ColorMatrix ColorMatrix cm = new ColorMatrix(); ColorMatrix Canvas ColorMatrix ColorMatrixColorFilter Paint paint.setcolorfilter(new ColorMatrixColorFilter(cm)); Choose Picture ColorMatrix Bitmap bmp = BitmapFactory.decodeStream(getContentResolver(). ë openinputstream(imagefileuri), null, bmpfactoryoptions); Bitmap alteredbitmap = Bitmap.createBitmap(bmp.getWidth(), ë bmp.getheight(),bmp.getconfig()); Canvas canvas = new Canvas(alteredBitmap); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); paint.setcolorfilter(new ColorMatrixColorFilter(cm)); Matrix matrix = new Matrix(); canvas.drawbitmap(bmp, matrix, paint); alteredimageview.setimagebitmap(alteredbitmap); chosenimageview.setimagebitmap(bmp);

92 CHAPTER 3 ColorMatrix (identity) Matrix 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 float 20 128 128 128 0 ( ) New Red Value = 1*128 + 0*128 + 0*128 + 0*0 + 0 New Blue Value = 0*128 + 1*128 + 0*128 + 0*0 + 0 New Green Value = 0*128 + 0*128 + 1*128 + 0*0 + 0 New Alpha Value = 0*128 + 0*128 + 0*128 + 1*0 + 0 128 1 (0)

93 2 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 ColorMatrix cm = new ColorMatrix(); cm.set(new float[] { 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 ); paint.setcolorfilter(new ColorMatrixColorFilter(cm)); (intensity) 3 15 ColorMatrix cm = new ColorMatrix(); float contrast = 2; cm.set(new float[] { contrast, 0, 0, 0, 0, 0, contrast, 0, 0, 0, 0, 0, contrast, 0, 0, 0, 0, 0, 1, 0 ); paint.setcolorfilter(new ColorMatrixColorFilter(cm));

94 CHAPTER 3 (color intensity) ColorMatrix cm = new ColorMatrix(); float brightness = -25; cm.set(new float[] { 1, 0, 0, 0, brightness, 0, 1, 0, 0, brightness, 0, 0, 1, 0, brightness, 0, 0, 0, 1, 0 ); paint.setcolorfilter(new ColorMatrixColorFilter(cm));

95 ColorMatrix cm = new ColorMatrix(); float contrast = 2; float brightness = -25; cm.set(new float[] { contrast, 0, 0, 0, brightness, 0, contrast, 0, 0, brightness, 0, 0, contrast, 0, brightness, 0, 0, 0, contrast, 0 ); paint.setcolorfilter(new ColorMatrixColorFilter(cm)); 3 16

96 CHAPTER 3 ColorMatrix (saturation) ColorMatrix cm = new ColorMatrix(); cm.setsaturation(.5f); paint.setcolorfilter(new ColorMatrixColorFilter(cm)); 1 (0) 1 (0) (grayscale) SDK Canvas Bitmap Bitmap Canvas Paint transfermode(xfermode) transfermode Xfermode PorterDuffXfermode (Thomas Porter) (Tom Duff) 1984 ACM SIGGRAPH PorterDuff Mode

97 : Paint : SRC DST : : : : : : : : :

98 CHAPTER 3 : : : 255 = / 255 : ( 255 ) = 255 (((255 ) (255 )) / 255) package com.apress.proandroidmedia.ch3.choosepicturecomposite; import java.io.filenotfoundexception; import android.app.activity; import android.content.intent; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.graphics.canvas; import android.graphics.paint; import android.graphics.porterduffxfermode; import android.net.uri; import android.os.bundle; import android.util.log; import android.view.display; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.imageview; public class ChoosePictureComposite extends Activity implements OnClickListener {

99 Choose Picture Composite Button OnClickListener Button Button Button static final int PICKED_ONE = 0; static final int PICKED_TWO = 1; boolean onepicked = false; boolean twopicked = false; Button choosepicture1, choosepicture2; ImageView Bitmap ImageView compositeimageview; Bitmap bmp1, bmp2; Canvas Paint Canvas canvas; Paint paint; @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); compositeimageview = (ImageView) this.findviewbyid(r.id.compositeimageview);

100 CHAPTER 3 choosepicture1 = (Button) this.findviewbyid(r.id.choosepicturebutton1); choosepicture2 = (Button) this.findviewbyid(r.id.choosepicturebutton2); choosepicture1.setonclicklistener(this); choosepicture2.setonclicklistener(this); Button OnClickListener onclick View Button which Button Gallery Gallery ACTION_PICK public void onclick(view v) { int which = -1; if (v == choosepicture1) { which = PICKED_ONE; else if (v == choosepicture2) { which = PICKED_TWO; Intent choosepictureintent = new Intent(Intent.ACTION_PICK, ë android.provider.mediastore.images.media.external_content_uri); startactivityforresult(choosepictureintent, which); onactivityresult startactivityforresult requestcode

101 Bitmap protected void onactivityresult(int requestcode, int resultcode, Intent intent) { super.onactivityresult(requestcode, resultcode, intent); if (resultcode == RESULT_OK) { Uri imagefileuri = intent.getdata(); if (requestcode == PICKED_ONE) { bmp1 = loadbitmap(imagefileuri); onepicked = true; else if (requestcode == PICKED_TWO) { bmp2 = loadbitmap(imagefileuri); twopicked = true; Bitmap Bitmap bmp1 (mutable) Bitmap Canvas Paint Bitmap(bmp1) Paint transfermode PorterDuffXfermode Bitmap Canvas ImageView Bitmap MULTIPLY if (onepicked && twopicked) { Bitmap drawingbitmap = Bitmap.createBitmap(bmp1.getWidth(), ë bmp1.getheight(), bmp1.getconfig()); canvas = new Canvas(drawingBitmap); paint = new Paint(); canvas.drawbitmap(bmp1, 0, 0, paint); paint.setxfermode(new PorterDuffXfermode(android.graphics. ë

102 CHAPTER 3 PorterDuff.Mode.MULTIPLY)); canvas.drawbitmap(bmp2, 0, 0, paint); compositeimageview.setimagebitmap(drawingbitmap); 1 Bitmap URI private Bitmap loadbitmap(uri imagefileuri) { Display currentdisplay = getwindowmanager().getdefaultdisplay(); float dw = currentdisplay.getwidth(); float dh = currentdisplay.getheight(); // ARGB_4444 Bitmap returnbmp = Bitmap.createBitmap((int) dw, (int) dh,bitmap.config.argb_4444); try { //. BitmapFactory.Options bmpfactoryoptions = new BitmapFactory.Options(); bmpfactoryoptions.injustdecodebounds = true; returnbmp = BitmapFactory.decodeStream(getContentResolver(). ë openinputstream(imagefileuri), null, bmpfactoryoptions); int heightratio = (int) Math.ceil(bmpFactoryOptions.outHeight / dh); int widthratio = (int) Math.ceil(bmpFactoryOptions.outWidth / dw); Log.v( HEIGHTRATIO, + heightratio); Log.v( WIDTHRATIO, + widthratio); // 1. if (heightratio > 1 && widthratio > 1) { if (heightratio > widthratio) { //. bmpfactoryoptions.insamplesize = heightratio;

103 else { //. bmpfactoryoptions.insamplesize = widthratio; //. bmpfactoryoptions.injustdecodebounds = false; returnbmp = BitmapFactory.decodeStream(getContentResolver(). ë openinputstream(imagefileuri), null, bmpfactoryoptions); catch (FileNotFoundException e) { Log.v( ERROR, e.tostring()); return returnbmp; 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 > <Button android:layout_width= fill_parent android:layout_height= wrap_content android:id= @+id/choosepicturebutton1 android:text= Choose Picture 1 /> <Button android:layout_width= fill_parent android:layout_height= wrap_content android:id= @+id/choosepicturebutton2 android:text= Choose Picture 2 /> <ImageView android:layout_width= wrap_content android:layout_height= ë wrap_content android:id= @+id/compositeimageview ></ImageView> </LinearLayout> transfermode 3 17 3 22

104 CHAPTER 3

105

106 CHAPTER 3

107 API