{"id":299,"date":"2023-05-16T13:04:11","date_gmt":"2023-05-16T13:04:11","guid":{"rendered":"https:\/\/itnotes.apjsoftwares.com\/?p=299"},"modified":"2023-05-16T13:04:11","modified_gmt":"2023-05-16T13:04:11","slug":"2d-and-3d-graphics","status":"publish","type":"post","link":"https:\/\/itnotes.apjsoftwares.in\/index.php\/2023\/05\/16\/2d-and-3d-graphics\/","title":{"rendered":"2D and 3D graphics"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><strong>Android graphics<\/strong><\/h3>\n\n\n\n<ul>\n<li>Android provides a huge set of 2D-drawing APIs that allow you to create graphics.<\/li>\n\n\n\n<li>Android has got visually appealing graphics and mind blowing animations.<\/li>\n\n\n\n<li>The Android framework provides a rich set of powerful APIS for applying animation to UI elements and graphics as well as drawing custom 2D and 3D graphics.<\/li>\n<\/ul>\n\n\n\n<p>Following are the three animation systems used in Android applications:<\/p>\n\n\n\n<p>1. Property Animation<\/p>\n\n\n\n<p>2. View Animation<\/p>\n\n\n\n<p>3. Drawable Animation<\/p>\n\n\n\n<p><strong>1. Property Animation<\/strong><\/p>\n\n\n\n<ul>\n<li>Property animation is the preferred method of animation in Android.<\/li>\n\n\n\n<li>This animation is the robust framework which lets you animate any properties of any objects, view or non-view objects.<\/li>\n\n\n\n<li>The android.animation provides classes which handle property animation.<\/li>\n<\/ul>\n\n\n\n<p><strong>2. View Animation<\/strong><\/p>\n\n\n\n<ul>\n<li>View Animation is also called Tween Animation.<\/li>\n\n\n\n<li>The android.view.animation provides classes which handle view animation.<\/li>\n\n\n\n<li>This animation can be used to animate the content of a view.<\/li>\n\n\n\n<li>It is limited to simple transformation such as moving, resizing and rotation, but not its background colour.<\/li>\n<\/ul>\n\n\n\n<p><strong>3. Drawable Animation<\/strong><\/p>\n\n\n\n<ul>\n<li>Drawable animation is implemented using the AnimationDrawable class.<\/li>\n\n\n\n<li>This animation works by displaying a running sequence of &#8216;Drawable&#8217; resources that is images, frame by frame inside a view object.<\/li>\n<\/ul>\n\n\n\n<p><strong>Canvas<\/strong><\/p>\n\n\n\n<ul>\n<li>Android graphics provides low level graphics tools such as canvases, colour, filters, points and rectangles which handle drawing to the screen directly.<\/li>\n\n\n\n<li>The Android framework provides a set of 2D-DRAWING APIs which allows users to provide their own custom graphics onto a canvas or to modify existing views to customise their look and feel.<\/li>\n<\/ul>\n\n\n\n<p><br>There are two ways to draw 2D graphics,<br>1. Draw your animation into a View object from your layout.<br>2. Draw your animation directly to a Canvas.<\/p>\n\n\n\n<p>Some of the important methods of Canvas Class are as follows<br>i) drawText()<br>ii) drawRoundRect()<br>iii) drawCircle()<br>iv) drawRect()<br>v) drawBitmap()<br>vi) drawARGB()<\/p>\n\n\n\n<ul>\n<li>You can use these methods in the onDraw() method to create your own custom user interface.<\/li>\n\n\n\n<li>Drawing an animation with a View is the best option to draw simple graphics that do not need to change dynamically and are not a part of a performance-intensive game. It is used when a user wants to display a static graphic or predefined animation.<\/li>\n\n\n\n<li>Drawing an animation with a Canvas is a better option when your application needs to redraw itself regularly. For example video games should be drawing to the Canvas on its own.<\/li>\n<\/ul>\n\n\n\n<p><strong>File name: MyView.java<\/strong><\/p>\n\n\n\n<p>public class MyView extends View<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public MyView(Context context)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super(context);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Override<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;protected void onDraw(Canvas canvas)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super.onDraw(canvas);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int radius;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;radius = 50;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Paint paint = newPaint();<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;paint.setStyle(Paint.Style.FILL);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;paint.setColor(Color.parseColor(&#8220;#CD5C5C&#8221;));<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;canvas.drawCircle(150,200, radius, paint);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;canvas.drawRoundRect(newRectF(20,20,100,100), 20, 20, paint);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;canvas.rotate(-45);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;canvas.drawText(&#8220;TutorialRide&#8221;, 40, 180, paint);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;canvas.restore();<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"247\" height=\"385\" src=\"https:\/\/itnotes.apjsoftwares.com\/wp-content\/uploads\/2023\/05\/image-77.png\" alt=\"\" class=\"wp-image-300\" srcset=\"https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2023\/05\/image-77.png 247w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2023\/05\/image-77-192x300.png 192w\" sizes=\"(max-width: 247px) 100vw, 247px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Android graphics Following are the three animation systems used in Android applications: 1. Property Animation&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/299"}],"collection":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/comments?post=299"}],"version-history":[{"count":1,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/299\/revisions"}],"predecessor-version":[{"id":301,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/299\/revisions\/301"}],"wp:attachment":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/media?parent=299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/categories?post=299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/tags?post=299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}