Graphics with Canvas.

Slides:



Advertisements
Similar presentations
CE881: Mobile and Social Application Programming Simon M. Lucas Layouts.
Advertisements

Graphics with Canvas, SurfaceView, and multitouch processing (panning and multitouch zoom) GraphicsWithCanvas_2012.pptx.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
Chapter 6 Jam! Implementing Audio in Android Apps.
Chapter 6: Jam! Implementing Audio in Android Apps.
Graphics.  2D Graphics using  ImageView  Canvas  ViewAnimation.
CS378 - Mobile Computing 2D Graphics A Crash Course in Using (Android) 2D Graphics Libraries.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
Who Am I And Why Am I Here I’m professor Stephen Fickas in CIS – you can call me Steve. I have a research group that works with mobile devices (since 1995!)
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.
Android sensors.
2D Graphics: Part 1. Android Graphics Libraries 2D Graphics –custom 2D graphics library in packages android.graphics android.graphics.drawable android.graphics.drawable.shapes.
Custom Views, Drawing, Styles, Themes, ViewProperties, Animations, oh my!
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Basic Drawing Techniques
2D Graphics: Part 2.
6-2 2D Graphics CSNB544 Mobile Application Development Thanks to Utexas Austin.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
Graphics Concepts CS 2302, Fall /3/20142 Drawing Paths.
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.
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 도형으로 안드로이드 캐릭터 만들기.
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 Threads. Threads Android will show an “ANR” error if a View does not return from handling an event within 5 seconds Or, if some code running in.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
ANDROID – A FIRST PROGRAM L. Grewe Using AndroidStudio –basic Android  Lets do a “Hello World Project”  Start up AndroidStudio (assume you have installed.
Android Application Lifecycle and Menus
CS378 - Mobile Computing User Interface Basics. User Interface Elements View – Control – ViewGroup Layout Widget (Compound Control) Many pre built Views.
Graphics in Android 1 CS7030: Mobile App Development.
Mobile Computing Lecture#12 Graphics & Animation.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
By: Eliav Menachi.  Android custom 2D graphics library  OpenGL ES 1.0 for high performance 3D graphics.
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.
CHAP 8. 그래픽. © 2012 생능출판사 All rights reserved 안드로이드에서의 그래픽 XML 파일로 그래픽이나 애니메이션을 정의한다. 그 리는 작업은 안드로이드 시스템이 담당한다. onDraw() 메소드 안에 draw...() 와 같은 메소드를 호.
Graphics & Animation Radan Ganchev Astea Solutions.
Lab7 – Appendix.
Lab7 – Advanced.
2D Graphics: Part 1.
Android Application 2D Graphics cs.
Lecture 3: Animation & Graphics
Android Introduction Hello World
Android N Amanquah.
GUI Programming Fundamentals
CS499 – Mobile Application Development
Lecture 3: Animation & Graphics
Lecture 8: Graphics By: Eliav Menachi.
2D Graphics: Part 2.
Android Layouts 24 July 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.
Reactive Android Development
תכנות ב android אליהו חלסצ'י.
Android Programming Lecture 6
Cannon Game App Android How to Program
Extend Text Editor to Draw shapes
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
Programming Mobile Applications with Android
Lecture 3: Animation & Graphics
Lecture 8: Graphics By: Eliav Menachi.
Cosc 5/4730 EmojiCompat library..
CIS 470 Mobile App Development
Presentation transcript:

Graphics with Canvas

Approaches for Graphics Load image from /res/drawable Best for static images OpenGL ES 3D graphics (i.e., transforms such as spin can be applied to graphical objects) Draw on Canvas or SurfaceView Canvas for drawing within the main thread SurfaceView is faster, and better for detailed graphics Note, if your main thread take too long, the OS will kill it, and it will be difficult to debug.

Drawable shapes Make new app, edu.eleg454.Graphics1 In onCreate is setContentView(R.layout.main) Instead of the view generated by R.layout.main, we use our own, which extends View In Graphics1 class, add private class MyView extends View { public MyView(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) { ShapeDrawable mDrawable = new ShapeDrawable(new OvalShape()); mDrawable.getPaint().setColor(0xff74AC23); mDrawable.setBounds(10, 10, 310, 60); mDrawable.draw(canvas); Then, in onCreate, replace setContentView(R.layout.main); with setContentView(new MyView(this)); Run Besides OvalShape, ArcShape, PathShape, RoundRectShape, and Shape

View Widget The previous method required us to replace setContentView(R.layout.main); This resulted in the entire view being controlled by our view E.g., we could not have a button in the view where we place the button with the layout editor To fix this, we add a view widget Move MyView to separate class Also, in MyView add public MyView(Context context, AttributeSet attrs) { super(context, attrs); } Go to main.xml graphical layout editor drag linear layout Drag text box So the layout is TextView, linear layout, TextView Go to main.xml (not the editor) Find second <LinearLayout ….> </LinearLayout> Before </LinearLayout>, add <edu.TestGraphics1.MyView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/View01"></edu.TestGraphics1.MyView> Note that edu.TestGraphics1.MyView is the name of the separate class. If another name is used, then this name should be changed Run

Canvas Drawing Canvas has many drawing functions, e.g., drawPath(Path path, Paint paint) Path: sequence of graphical objects Path path = new Path(); Make line between two points path.moveTo(10,10); // starting place path.lineTo(60,60); add circle somewhere path.addCircle(50,250,20, Path.Direction.CCW); Paint – for setting color and line width Paint paint = new Paint(); paint.setDither(true); paint.setColor(Color.RED); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setStrokeJoin(Paint.Join.ROUND); paint.setStrokeCap(Paint.Cap.ROUND); paint.setStrokeWidth(2); Draw view canvas.drawPath(path, paint); run

notes Use invalidate() to force redraw In TestGraphics, add variable MyView myView; In TestGraphics.onCreate(), add myView = (MyView) findViewById(R.id.View01); Then myView.invalidate(); will force redraw Is canvas documentation for more graphics E.g., drawBitmap has several functions Avoid declaring and setting variables in onDraw, instead, setting them elsewhere and access them from draw Use SurfaceView for faster screen drawing