Building Apps with Graphics & Animation. Displaying Bitmaps Efficiently Loading Large Bitmaps Efficiently Caching Bitmaps Managing Bitmap Memory Displaying.

Slides:



Advertisements
Similar presentations
Put your photos into PowerPoint Insert, crop, and format pictures Youve got photos and you want to display them in a slide show. The first thing you need.
Advertisements

CE881: Mobile and Social Application Programming Simon M. Lucas Layouts.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
COMPUTER GRAPHICS CS 482 – FALL 2014 NOVEMBER 10, 2014 GRAPHICS HARDWARE GRAPHICS PROCESSING UNITS PARALLELISM.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
Go through this show in OpenOffice Impress by using the right scrollbar or clicking individual slide thumbnails on the left side. This hands-on demo is.
© 2011 Delmar, Cengage Learning Chapter 13 Preparing Graphics for the Web.
Windows XP Basics OVERVIEW Next.
Processing Processing is a simple programming environment that was created to make it easier to develop visually oriented applications with an emphasis.
CS378 - Mobile Computing 3D Graphics.
App Development on Android
Ch 1 Intro to Graphics page 1CS 367 First Day Agenda Best course you have ever had (survey) Info Cards Name, , Nickname C / C++ experience, EOS experience.
Optimizing picture file size. Three things you can do to lower file size  Lower the resolution  Crop the picture  Save with a file format that uses.
1 CGS1060 Mobile UIs Copyright 2012 by Janson Industries.
The following slide has the same photo at three resolutions. Each version has been resized in Powerpoint to occupy the entire width of the screen. Remember.
MULTIMEDIA TECHNOLOGY SMM 3001 MEDIA - GRAPHICS. In this chapter how the computer creates, stores, and displays graphic images how the computer creates,
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
Creating a MagicInfo Pro Screen Template
1 Computer Graphics Week13 –Shading Models. Shading Models Flat Shading Model: In this technique, each surface is assumed to have one normal vector (usually.
11 Games and Content Session 4.1. Session Overview  Show how games are made up of program code and content  Find out about the content management system.
1 Bitmap Graphics It is represented by a dot pattern in which each dot is called a pixel. Each pixel can be in any one of the colors available and the.
CHAPTER 4 Images XNA Game Studio 4.0. Objectives Find out how the Content Manager lets you add pictures to Microsoft XNA games. Discover how pictures.
Zhonghua Qu and Ovidiu Daescu December 24, 2009 University of Texas at Dallas.
Image Synthesis Rabie A. Ramadan, PhD 3. 2 Our Problem.
CSE 381 – Advanced Game Programming Basic 3D Graphics
Prezentacja autorstwa:
Create your own template
CARLSON SOFTWARE CONFERENCE DANIEL V. SYPERSMA VICTOR GRAPHICS.
Higher Computing Computer Systems S. McCrossan 1 Higher Grade Computing Studies 1. Data Representation Data Representation – Why do we use binary? simplicity,
DUE Hello World on the Android Platform.
Week 2 - Wednesday CS361.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
Image Synthesis Rabie A. Ramadan, PhD D Images.
XP New Perspectives on Microsoft PowerPoint 2002 Tutorial 2 1 Microsoft PowerPoint 2002 Tutorial 2 – Applying and Modifying Text and Graphic Objects.
Image Synthesis Rabie A. Ramadan, PhD 1. 2 About my self Rabie A. Ramadan My website and publications
Android architecture & setting up. Android operating system comprises of different software components arranges in stack. Different components of android.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
CS 480/680 Intro Dr. Frederick C Harris, Jr. Fall 2014.
به نام خدا تنظیم کننده : فرانه حدادی استاد : مهندس زمانیان تابستان 92.
Microsoft ® Office PowerPoint ® 2003 Training Create your own template [Your company name] presents:
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
Introduction to Flash Animation CS 318. Topics Introduction to Flash and animation The Flash development environment Creating Flash animations  Layers.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Introduction to Processing. 2 What is processing? A simple programming environment that was created to make it easier to develop visually oriented applications.
CS378 - Mobile Computing Responsiveness. An App Idea From Nifty Assignments Draw a picture use randomness Pick an equation at random Operators in the.
Lecture 7: Intro to Computer Graphics. Remember…… DIGITAL - Digital means discrete. DIGITAL - Digital means discrete. Digital representation is comprised.
Project Two Adding Web Pages, Links, and Images Define and set a home page Add pages to a Web site Describe Dreamweaver's image accessibility features.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
1 Graphics CSCI 343, Fall 2015 Lecture 5 Color in WebGL.
Lesson 6 Formatting Cells and Ranges. Objectives:  Insert and delete cells  Manually format cell contents  Copy cell formatting with the Format Painter.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
The desktop (overview) Working with desktop icons The desktop is the main screen area that you see after you turn on your computer and log on to Windows.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
 Learn how you can use the shader through OpenGL ES  Add texture on object and make the object have a different look!!
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
GPU Computing for GIS James Mower Department of Geography and Planning University at Albany.
By: Eliav Menachi.  Android custom 2D graphics library  OpenGL ES 1.0 for high performance 3D graphics.
Adobe Flash Professional CS5 – Illustrated Unit E: Optimizing and Publishing a Movie.
Adding Tables to Slides Lesson 5. Software Orientation Tables are designed to organize data in columns and rows, as shown at right. The Table Tools Design.
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
Chapter 2 Starting a Project
Flash Interface, Commands and Functions
Introduction to OpenGL
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
CS297 Graphics with Java and OpenGL
Introduction to OpenGL
Presentation transcript:

Building Apps with Graphics & Animation

Displaying Bitmaps Efficiently Loading Large Bitmaps Efficiently Caching Bitmaps Managing Bitmap Memory Displaying Bitmaps in Your UI Displaying Graphics with OpenGL ES Building an OpenGL ES Environment Defining Shapes Drawing Shapes Applying Projection Adding Motion Responding To Touch Events

Adding Animations Crossfading To Views Property Animation Using ViewPager for Screen Slide

What is Bitmap? Most images you see on your computer are composed of bitmaps. A bitmap is a map of dots, or bits (hence the name), that looks like a picture as long you are sitting a reasonable distance away from the screen. Because bitmap images are made up of a bunch of dots, if you zoom in on a bitmap, it appears to be very blocky.

Formats ALPHA_8 To store alpha masks(font cache, etc.) ARGB_4444 (4 bits no precision) Not good to use ARGB_8888 (the default from the Android 2.3 onward) Full color, good for pictures RGB_565 No alpha channel, saves memory

Loading Large Bitmaps Efficiently Mobile devices typically have as little as 16 MB of memory for a single application. Applications should be optimized to perform under this minimum memory limit. Bitmaps take a lot of memory, for example the Galaxy Nexus uses with a 5 Megapixel photo as default memory configuration (ARGB_8888) 19 MB, which is already too much. So ideally you only want to load a lower resolution version in memory

Read Bitmap Dimensions and Type The BitmapFactory class provides severel decoding methods Example: decodeByteArray(), decodeFile(), decodeResource() Not to get a OutOfMemory exception you also need to know outWidth, outHeight and outMimeType This will allow you to read the dimensions out of the bitmap Useful, because it makes no sense to load a 1024x768 pixel image which eventually only need to be displayed as a 128x96 pixel thumbnail Set inSampleSize to true to tell the decoder to load a smaller version

Caching Bitmaps Loading only a single bitmap in the user interface is straightforward Loading more bitmaps in the user interface is complicated Don’t know how many images are still coming Garbage collector would delete immediately No fluent process so use memory disk cache

Memory Cache A memory cache offers fast access to bitmaps at the cost of taking up valuable application memory. Use LruCache which is particularly well suited to the task of caching bitmaps First think about how memory intensive the application is, how many images should be shown on the screen, density of screen size That’s for getting the cache right so that there will be no overhead if the cache is too small or too large (java.lang.OutOfMemory)

Use a Disk Cache Memory easy gets filled up If application gets interrupted, for example by a phone call, memory would get killed and the memory cache destroyed. Disk Cache would store the bitmap in a background thread Not destroyed by interruption Slower to load

Handle Configuration Changes Runtime configuration changes, such as a screen orientation change, cause Android to destroy and restart the running activity with the new configuration Avoiding this problem add a Fragment code to LruCache which helps you to store the files in memory and reattach them after the new configuration change is done

Managing Bitmap Memory On Android (API level 10) and lower, using recycle() is recommended. If you’re displaying large amounts of bitmap data in your app, you’re likely to run into OutOfMemoryError errors. You should use recycle() only when you are sure that the bitmap is no longer being used. Android 3.0 (API Level 11) introduces the BitmapFactory.Options.inBitmap field. If this option is set, decode methods that take the Options object will attempt to reuse an existing bitmap when loading content.

API Levels generally mean that as a programmer, you can communicate with the devices' built in functions and functionality. As the API level increases, functionality adds up (although some of it can get deprecated). Choosing an API level for an application development should take at least two things into account: Current distribution - How many devices can actually support my application, if it was developed for API level 9, it cannot run on API level 8 and below, then "only" around 60% of devices can run it. Current distribution Choosing a lower API level may support more devices but gain less functionality for your app. you may also work harder to achieve features you could've easily gained if you chose higher API level. Android API levels can be divided to three main groups (not scientific, but what the heck): Android (API levels 3-10) - Android made specifically for smartphones. Android (API levels 11-13) - Honeycomb, Android made for tablets. Android 4 (API levels 14-) - Ice Cream Sandwich - Current generation, a big merge with tons of additional functionality, totally revamped Android version, for both phone and tablets.

Displaying Bitmaps in Your UI The swipe view pattern is an excellent way to navigate the detail view of an image gallery. You can implement this pattern using a ViewPager (code) component backed by a PagerAdapter (code).

Displaying Graphics with OpenGL ES Android includes support for high performance 2D and 3D graphics with the Open Graphics Library (OpenGL), specifically, the OpenGL ES API. OpenGL is a cross-platform graphics API that specifies a standard software interface for 3D graphics processing hardware.

OpenGL

SurfaceView SurfaceView is just one way to incorporate OpenGL ES graphics into your application. For a full-screen or near-full screen graphics view This class is a View where you can draw and manipulate objects using OpenGL API calls and is similar in function to a SurfaceView

Define Shapes Possible to define three-dimension shapes in OpenGL ES. Example: Draw a triangle Define its coordinates in a vertex array By default, OpenGL ES assumes a coordinate system where [0,0,0] (X,Y,Z) specifies the center of the GLSurfaceView frame [1,1,0] is the top right corner of the frame and [-1,-1,0] is bottom left corner of the frame.

Draw a Shape Drawing a defined shape using OpenGL ES 2.0 requires a significant amount of code, because you must provide a lot of details to the graphics rendering pipeline. Specifically, you must define the following: Vertex Shader - OpenGL ES graphics code for rendering the vertices of a shape. Fragment Shader - OpenGL ES code for rendering the face of a shape with colors or textures. Program - An OpenGL ES object that contains the shaders you want to use for drawing one or more shapes

private final String vertexShaderCode = "attribute vec4 vPosition;" + "void main() {" + " gl_Position = vPosition;" + "}"; private final String fragmentShaderCode = "precision mediump float;" + "uniform vec4 vColor;" + "void main() {" + " gl_FragColor = vColor;" + "}";

Applying Projection This transformation adjusts the coordinates of drawn objects based on the width and height of the GLSurfaceView where they are displayed. Without this calculation, objects drawn by OpenGL ES are skewed by the unequal proportions of the view window. A projection transformation typically only has to be calculated when the proportions of the OpenGL view are established or changed

Adding Motion / Responding to Touch Events OpenGL ES provides additional capabilities for moving and transforming drawn objects in three dimensions or in other unique ways to create compelling user experiences. Interact with OpenGl ES graphics In order to make your OpenGL ES application respond to touch events, you must implement the onTouchEvent() method in your GLSurfaceView class

Adding Animations Animations can add subtle visual cues that notify users about what's going on in your app and improve their mental model of your app's interface. Animations are especially useful when the screen changes state, such as when content loads or new actions become available. Animations can also add a polished look to your app, which gives your app a higher quality feel.

Property Animation The property animation system is a robust framework that allows you to animate almost anything. You can define an animation to change any object property over time, regardless of whether it draws to the screen or not.

Crossfading Two Views Crossfade animation is if you change from one UI component to another. While the application is doing that, mostly it has to load something. During this time you can show an animation that the transitions doesn’t feel that abrupt or hurried. src/CrossfadeActivity.java _layout/activity_crossfade.xml menu/activity_crossfade.xml

Using ViewPager for Screen Slides Screen slides are transitions between one entire screen to another and are common with UIs like setup wizards or slideshows. This lesson shows you how to do screen slides with a ViewPager provided by the support library.ViewPager s can animate screen slides automatically. Here's what a screen slide looks like that transitions from one screen of content to the next: src/ScreenSlidePageFragment.java src/ScreenSlideActivity.java layout/activity_screen_slide.xml layout/fragment_screen_slide_page.xml

END