© 2012 생능출판사 All rights reserved CHAP 8. 그래픽. © 2012 생능출판사 All rights reserved 안드로이드에서의 2 차원 그래픽 사용 방법 1) XML 파일로 그래픽이나 애니메이션을 정의한다. 그리는 작업은 안드로이드 시스템이.

Slides:



Advertisements
Similar presentations
객체지향프로그래밍강원대학교 객체지향프로그래밍 제 4 주 – 그래픽 프로그래밍 기초 1. 객체지향프로그래밍강원대학교 제 5 장 그래픽 프로그래밍 제 4 주 강의 목표 간단한 그래픽 프로그램을 작성하는 법을 배운다. 도형을 그리고 색을 선택하는 법을 배운다. 2.
Advertisements

Graphics with Canvas, SurfaceView, and multitouch processing (panning and multitouch zoom) GraphicsWithCanvas_2012.pptx.
Graphics.  2D Graphics using  ImageView  Canvas  ViewAnimation.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Android Form Elements. Views Provide common UI functionality Form elements: text area, button, radio button, checkbox, dropdown list, etc. Date and time.
My own View Android development Maarten Pennings 2011 oct 14.
Crash Course in Android Development. 2 Content  Installing the ADT  Hardware and OS requirements  Java  ADT Bundle  Eclipse Project Setup  Drawing.
2D Graphics: Part 1. Android Graphics Libraries 2D Graphics –custom 2D graphics library in packages android.graphics android.graphics.drawable android.graphics.drawable.shapes.
Graphics in Android 1 Fall 2012 CS2302: Programming Principles.
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Custom Views, Drawing, Styles, Themes, ViewProperties, Animations, oh my!
Basic Drawing Techniques
2D Graphics: Part 2.
4 출 력.
Android Tutorial Team 3 Jerry Yu Mayank Mandava Mu Du Will Wangles.
CHAP 10. 고급 위젯. © 2012 생능출판사 All rights reserved 어댑터 뷰 어댑터 뷰 (AdapterView) 는 배열이나 파일, 데이터 베이스에 저장된 데이터를 화면에 표시할 때 유용한 뷰.
8-3. 버튼 천안천일고등학교 류빈. 1. 가장 기본적인 위젯인 TextView 를 통해 위젯의 일반 적인 특징과 프로그래밍 방법을 상세하게 연구해보고 버튼의 사용 방법을 익힌다. 학습목표 1. 리소스 2. 텍스트 뷰 3. 버튼 학습내용 2.
2012 내장형 시스템 설계  Full Color LED 디바이스 구성  Full Color LED 디바이스 드라이버  Full Color LED JNI 라이브러리 작성  Full Color LED 안드로이드 App 구현  JNI 라이브러리.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
Import import android.graphics.Bitmap; import android.widget.ImageView;
Android Graphics Library. Color Android colors are represented with four numbers, one each for alpha, red, green, and blue (ARGB). Each component can.
로봇 모니터링 1/2 UNIT 20 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Message Queue Handler 2.
5-1. 캔버스 천안천일고등학교 류빈 1.Canvas 와 Paint 객체를 통해 화면에 원하는 도형을 그리고 속성을 변경하는 기본적인 방법에 대해 소개 한다. 2. 토스트로 메시지를 출력하는 방법과 스피커를 통해 소리를 출력하는 방법에.
Custom Widget 1 UNIT 26 로봇 SW 콘텐츠 교육원 조용수. 캔버스 public void drawColor(int color) 2 public class ControllerView extends View { public ControllerView(Context.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Ch3. 캔버스 활용 3-2 도형으로 안드로이드 캐릭터 만들기.
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
Announcements Homework #2 will be posted after class due Thursday Feb 7, 1:30pm you may work with one other person No office hours tonight (sorry!) I will.
Cosc 5/4730 Android drawing. Screen support Android is the OS and is used a many different hardware created by different vendors. – Screen size For simplicity,
Android Using Menus Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © CommonsWare, LLC. ISBN:
CHAP 11. 액티비티와 인텐트.
CHAP 8. 고급 그래픽과 O PEN GL. © 2012 생능출판사 All rights reserved C ANVAS 클래스와 P AINT 클래스.
CHAP 8. 그래픽.
목차 한국기술교육대학교 강사: 김 영 준 ㈜헬로앱스 1일차 아두이노 제어 실습
Android and s Ken Nguyen Clayton state University 2012.
아주대학교 LifecareScienceLAB Android Seminar 3 rd class Android Software Development 2011/05/04 – p.m. 06:00 – 팔달관 409 호 아주대학교.
Graphics in Android 1 CS7030: Mobile App Development.
Custom Widget 2 UNIT 27 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Custom Widget –Canvas 를 이용하여 Custom Widget 을 만든다. 2.
Mobile Computing Lecture#12 Graphics & Animation.
CHAP 14. 프로세스와 스레드. © 2012 생능출판사 All rights reserved 다중 스레딩 하나의 애플리케이션이 동시에 여러 가지 작업을 하 는 것 이들 작업은 스레드 (thread) 라고 불린다.
CHAP 6. 이벤트 처리. © 2012 생능출판사 All rights reserved 폴링과 이벤트 구동 방식.
CHAP 7. 메뉴와 대화상자. © 2012 생능출판사 All rights reserved 메뉴의 종류 옵션 메뉴 : 사용자가 MENU 키를 누를 때 나타난다. 컨텍스트 메뉴 : 컨텍스트 메뉴는 사용자가 화면을 일정 시간 이상으로 길게 누르면 나타나는 메뉴이다.
아주대학교 LifecareScienceLAB Android Seminar 2 nd class Android Software Development 2011/04/13 – p.m. 06:00 – 팔달관 409 호 아주대학교.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
David Sutton 2D GRAPHICS IN ANDROID. INTRODUCTION AND OUTLINE  In this week’s session we will create a simple Kaleidoscope application. Topics that will.
Android 基本 I/O. 基本 I/O 介面元件 在此節中主要介紹常見的 I/O 使用者介 面元件 – Button, TextView, 以及 EditText , 學習者可以學會: – Android 的視窗表單設計 res/layout/main.xml – Android SDK –
Lecture 3: Animation & Graphics Topics: Animation, Graphics, Drawing Date: Feb 2, 2016.
You have to remember that  To create an AVD(Android Virtual Device)  The Structure of Android Project  XML Layout  The advantage of XML Layout  Android.
CHAP 8. 그래픽. © 2012 생능출판사 All rights reserved 안드로이드에서의 그래픽 XML 파일로 그래픽이나 애니메이션을 정의한다. 그 리는 작업은 안드로이드 시스템이 담당한다. onDraw() 메소드 안에 draw...() 와 같은 메소드를 호.
2D Graphics: Part 1.
Lecture 3: Animation & Graphics
Android Introduction Hello World
UNIT 11 로봇 전화번호부 3/4 로봇 SW 콘텐츠 교육원 조용수.
GUI Programming Fundamentals
滑動版面 建國科技大學 資管系 饒瑞佶 2013/7 V1.
CS499 – Mobile Application Development
Lecture 3: Animation & Graphics
Android Introduction Hello World.
Android External Resources
2D Graphics: Part 2.
תכנות ב android אליהו חלסצ'י.
Android Programming Lecture 6
Graphics with Canvas.
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
Lecture 3: Animation & Graphics
Adding Components to Activity
BLP 4216 MOBİL UYGULAMA GELİŞTİRME-2
CIS 470 Mobile App Development
Presentation transcript:

© 2012 생능출판사 All rights reserved CHAP 8. 그래픽

© 2012 생능출판사 All rights reserved 안드로이드에서의 2 차원 그래픽 사용 방법 1) XML 파일로 그래픽이나 애니메이션을 정의한다. 그리는 작업은 안드로이드 시스템이 담당한다. 2) onDraw( ) 메소드 안에 draw...( ) 와 같은 메소드를 호출하여 직접 캔버스에 코드로 그린다.

© 2012 생능출판사 All rights reserved 커스텀 뷰를 사용하여 그리기 ( 기초 이론 ) 1) onDraw 메소드를 View 클래스에서 오버라이딩 해야 함. 2) onDraw 메소드의 매개 변수로 전달되는 Canvas 객체 를 이용하여 그리기 행위를 정의할 수 있음. 3) 그러나 Canvas 객체는 기본적으로 흰 바탕에 검정색 4) 다양한 색상과 선의 굵기, 모양 등을 사용하기 위해 Paint 클래스를 사용해 속성 설정

© 2012 생능출판사 All rights reserved View 클래스의 onDraw( ) 메소드에 대해서..  protected void onDraw(Canvas canvas)  protected 인 이유 - 안드로이드 시스템에 의해 뷰의 갱신이 필요할 때 해당 클래스 내부적으로 적당한 타이밍에 자동으로 호출되어지는 메소드

© 2012 생능출판사 All rights reserved View 클래스의 onDraw( ) 메소드에 대해서.. public class MyView extends View {... 생략... protected void onDraw(Canvas canvas) { // 뷰의 배경색을 붉은 색으로 지정한다. canvas.drawColor(Color.RED); }... 생략... }

© 2012 생능출판사 All rights reserved Canvas 클래스란 …  선, 원, 면 등 그림을 그리는 행위 를 정의한 클래스  그리기 작업 수행가능한 draw( ) 계열의 메소드 존재. (p ) - drawPoint, drawLine, drawRect, drawCircle, drawText, drawRoundRect, drawOval, drawArc, drawLines, drawColor 등

© 2012 생능출판사 All rights reserved Canvas 클래스란 … protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(Color.RED); canvas.drawColor(Color.WHITE); canvas.drawCircle(100, 100, 10, paint); canvas.drawLine(100, 100, 110, 150, paint) }

© 2012 생능출판사 All rights reserved Paint 클래스란 …  그리기 속성 을 가지고 있는 클래스  선 또는 면의 색상, 선의 형식, 폰트종류 폰트형식, 이미지필터, 안티앨리어싱 여부 디더링, 투명화 등 (p )

© 2012 생능출판사 All rights reserved 커스텀 뷰를 사용하여 그리기... class MyView extends View { public MyView(Context context) { super(context); setBackgroundColor(Color.YELLOW); protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(Color.RED); canvas.drawLine(20, 50, 100, 50, paint); canvas.drawRect(10, 110, 100, 150, paint); canvas.drawCircle(50, 200, 30, paint); canvas.drawText(" 텍스트도 그릴 수 있습니다 ", 10, 300, paint); }

© 2012 생능출판사 All rights reserved 커스텀 뷰를 사용하여 그리기 public class GraphicsActivity extends Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MyView w = new MyView(this); setContentView(w); }

© 2012 생능출판사 All rights reserved 몇 개의 기초 도형 protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(Color.YELLOW); canvas.drawColor(Color.BLUE); canvas.drawRoundRect(new RectF(10,10,110,110), 5, 5, paint); canvas.drawOval(new RectF(150,10,250,110), paint); paint.setColor(Color.RED); canvas.drawArc(new RectF(10,120,110,220), 120, 270, true, paint); paint.setColor(Color.YELLOW); float[] pts={ 10, 250, 100, 270, 100, 270, 20, 290, 20, 290, 120, 300}; canvas.drawLines(pts, paint); }

© 2012 생능출판사 All rights reserved 커스텀 뷰를 XML 에서 참조하 기... public class CustomView extends View { public CustomView(Context context) { super(context); setBackgroundColor(Color.YELLOW); } public CustomView(Context context, AttributeSet attrs) { super(context); setBackgroundColor(Color.YELLOW); protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(Color.RED); canvas.drawArc(new RectF(10, 120, 110, 220), 120, 270, true, paint); }

© 2012 생능출판사 All rights reserved 커스텀 뷰를 XML 에서 참조하기 <LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <kr.co.company.graphiccustomview.CustomView android:layout_width="fill_parent" android:layout_height="fill_parent" />

© 2012 생능출판사 All rights reserved 색상  색의 3 원색인 Red, Green, Blue 성분을 8 비트로 표시  paint.setColor(0xFF0000);  paint.setColor(Color.RED);

© 2012 생능출판사 All rights reserved 선의 스타일 FILL 도형의 내부를 채운다. FILL_AND_STROKE 도형의 내부를 채우면서 외곽선도 그린다. STROKE 도형의 외곽선만 그린다.  선 스타일 설정은  setStyle(Paint.Style.STROKE);  setStyle(Paint.Style.Fill);

© 2012 생능출판사 All rights reserved 앤티 에일리어싱  paint.setAntiAlias(true);

© 2012 생능출판사 All rights reserved 원호그리기 class MyView extends View { private Paint mPaints, mFramePaint; private RectF mBigOval; private float mStart, mSweep; private static final float SWEEP_INC = 2; private static final float START_INC = 15; public MyView(Contextcontext) { super(context); mPaints = new Paint(); mPaints.setAntiAlias(true); mPaints.setStyle(Paint.Style.FILL); mPaints. setColor(0x88FF0000);.setColor(0x88FF0000); mFramePaint = new Paint(); mFramePaint.setAntiAlias(true); mFramePaint.setStyle(Paint.Style.STROKE);); mFramePaint.setStrokeWidth(3); mFramePaint.setColor(0x8800FF00); mBigOval = new RectF(40, 10,280, 250); }

© 2012 생능출판사 All rights reserved protected void onDraw(Canvas canvas) { canvas.drawColor(Color.YELLOW); canvas.drawRect(mBigOval, mFramePaint); canvas.drawArc(mBigOval, mStart, mSweep, false, mPaints); mSweep += SWEEP_INC; if (mSweep >360) { mSweep -= 360; mStart += START_INC; if (mStart >= 360) mStart -= 360; } invalidate(); } public class MyArcActivity extends Activity { protected void onCreate(BundlesavedInstanceState) { super.onCreate(savedInstanceState); setContentView(new MyView(this)); }

© 2012 생능출판사 All rights reserved 폰트 메소드 static Typeface create (Typeface family, int style) static Typeface create (String familyName, int style) Typeface 객체는 Typeface 클래스 내부의 create() 메소드로 생성된다. family: 폰트 이름, DEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, SERIF 중의 하나 style: 폰트 스타일, NORMAL, BOLD, ITALIC, BOLD_ITALIC 중의 하나 위의 메소드들은 주어진 폰트와 스타일에 가장 일치하는 Typeface 객체를 생성한다. 이 메소드는 주로 이미 존재하는 폰트로부터 새로운 스타일의 폰트를 생성하고자 할 때 호출한다. 만약 family가 null이면 디폴트 폰트 패밀리를 선택한다. Typeface setTypeface (Typeface typeface) 폰트를 typeface로 변경한다. void drawText(String text, float x, float y, Paint paint) void drawText(String text, int start, int end, float x, float y, Paint paint) void drawText(char[] text, int index, int count, float x, float y, Paint paint) 텍스트를 화면에 그린다.

© 2012 생능출판사 All rights reserved 폰트 protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setAntiAlias(true); paint.setTextSize(25); Typeface t; t = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL); paint.setTypeface(t); canvas.drawText("DEFAULT 폰트 ", 10, 100, paint); t = Typeface.create(Typeface.DEFAULT_BOLD, Typeface.NORMAL); paint.setTypeface(t); canvas.drawText("DEFAULT_BOLD 폰트 ", 10, 150, paint); t = Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL); paint.setTypeface(t); canvas.drawText("MONOSPACE 폰트 ", 10, 200, paint); t = Typeface.create(Typeface.SERIF, Typeface.NORMAL); paint.setTypeface(t); canvas.drawText("SERIF 폰트 ", 10, 250, paint); t = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL); paint.setTypeface(t); canvas.drawText("SANS_SERIF 폰트 ", 10, 300, paint); }

© 2012 생능출판사 All rights reserved 폰트 예제 실행 결과

© 2012 생능출판사 All rights reserved 외부 폰트 사용  폰트 파일을 구하여 프로젝트의 asset 폴더로 protected void onDraw(Canvas canvas) { Typeface myFont; Paint paint = new Paint(); paint.setAntiAlias(true); myFont = Typeface.createFromAsset(getContext().getAssets(), "animeace2_ital.ttf"); paint.setTypeface(myFont); paint.setTextSize(25); canvas.drawText("This is a New Font!!!", 10, 100, paint); canvas.drawText("Have Fun!!!", 10, 200, paint); }

© 2012 생능출판사 All rights reserved 패스 그리기  패스 (path) 는 복잡한 기하학적인 경로를 표현  패스는 직선과 타원, 곡선으로 이루어질 수 protected void onDraw(Canvas canvas) { Path path = new Path(); Paint paint = new Paint(); paint.setStyle(Paint.Style.STROKE); path.moveTo(20, 100); path.lineTo(100, 200); path.cubicTo(150, 30, 200, 300, 300, 200); paint.setColor(Color.BLUE); canvas.drawPath(path, paint); paint.setStyle(Paint.Style.FILL); paint.setTextSize(50); canvas.drawTextOnPath("This is a test!!", path, 0, 0, paint); }

© 2012 생능출판사 All rights reserved 이미지 표시  리소스 폴더에 이미지 파일를 복사한다.  예를 들어서 android.png 파일을 프로젝트의 res/drawable-mdpi 폴더에 복사  프로그램에서는 R.drawable.android 로 참조  지원되는 파일 형식은 PNG ( 선호 ), JPG ( 가능 ), GIF ( 권장되지 않음 )

© 2012 생능출판사 All rights reserved 이미지 표시하기 : ImageView 사용 <LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent“ android:layout_height="wrap_content" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" />

© 2012 생능출판사 All rights reserved 코드로 화면에 이미지 표시 class MyView extends View { public MyView(Context context) { super(context); setBackgroundColor(Color.YELLOW); protected void onDraw(Canvas canvas) { Paint paint = new Paint(); Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.android); canvas.drawBitmap(b, 0, 0, null); } public class ImageDispActivity extends Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MyView w = new MyView(this); setContentView(w); }

© 2012 생능출판사 All rights reserved 이미지 크기 변환... protected void onDraw(Canvas canvas) { Paint paint = new Paint(); Matrix m= new Matrix(); m.preScale(1, -1); Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.house); Bitmap mb = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, false); Bitmap sb = Bitmap.createScaledBitmap(b, 200, 200, false); canvas.drawBitmap(mb, 0, 0, null); canvas.drawBitmap(sb, 100, 100, null); }...

© 2012 생능출판사 All rights reserved 도형 객체  사각형이나 원 같은 도형을 객체로 표시한다.  Drawable 객체  XML 로 객체를 생성  코드로 객체를 생성

© 2012 생능출판사 All rights reserved XML 로 도형 객체 정의 <shape xmlns:android=" android:shape=["rectangle" | "oval" | "line" | "ring"] >

© 2012 생능출판사 All rights reserved XML 로 도형 객체 정의 : 예제 <shape xmlns:android=" android:shape="oval">

© 2012 생능출판사 All rights reserved XML 로 도형 객체 정의 : 예제... LinearLayout mLinearLayout; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 리니어 레이아웃을 생성한다. mLinearLayout = new LinearLayout(this); //ImageView 객체를 생성한다. ImageView I = new ImageView(this); i.setImageDrawable(R.drawable.oval); i.setMinimumHeight(100); i.setMinimumWidth(100); //ImageView 를 레이아웃에 추가한다. mLinearLayout.addView(i); setContentView(mLinearLayout); }...

© 2012 생능출판사 All rights reserved 소스코드로 도형 객체 정의... protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 리니어 레이아웃을 생성한다 mLinearLayout = new LinearLayout(this); //Drawable 객체를 소스코드로 생성한다. ShapeDrawable oval = new ShapeDrawable(new OvalShape()); oval.setIntrinsicHeight(100); oval.setIntrinsicWidth(100); oval.getPaint().setColor(Color.RED); ImageView i = new ImageView(this); i.setImageDrawable(oval);// 여기서 설정하면 된다. // ImageView 를 레이아웃에 추가한다 mLinearLayout.addView(i); setContentView(mLinearLayout); }...