{"id":479,"date":"2011-07-07T23:02:00","date_gmt":"2011-07-07T23:02:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/android-game-development-displaying-images-with-android.html"},"modified":"2012-10-21T20:01:33","modified_gmt":"2012-10-21T20:01:33","slug":"android-game-development-displaying","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html","title":{"rendered":"Android Game Development &#8211; Displaying Images with Android"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">Before moving to the actual game loop let\u2019s display some graphics so we can get some measurements done. If you haven\u2019t checked it out please do as it is imperative that you understand how a thread updates the screen. You can check it out <a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-basic-game_05.html\">here<\/a>.<\/p>\n<p>Displaying an image using Android is extremely simple.<br \/>\nTo scale the problem down we will just display the image in the top left corner. We need an image to display. I prefer .png formats and I have just created one named droid_1.png. The size of the image is 20\u00d720 pixels. You can use whatever tool you like. I use Gimp or Photoshop.<\/p>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/08\/droid_1.png\"><img decoding=\"async\" border=\"0\" src=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/08\/droid_1.png\" \/><\/a><\/div>\n<p>To make it available for your application just copy the image into the <strong><i>\/res\/drawable-mdpi<\/i><\/strong> directory (the easiest way is to drag and drop it there).<br \/>\nI have chosen mdpi which stands for normal screen medium density. To read on screen types check the <a href=\"http:\/\/developer.android.com\/guide\/practices\/screens_support.html\">android documentation<\/a>.<\/p>\n<p>Modify the <strong><i>MainGamePanel.java<\/i><\/strong> class and change the <strong><i>onDraw(Canvas canvas)<\/i><\/strong> method to look like this:<\/p>\n<pre class=\"brush:java\">protected void onDraw(Canvas canvas) {\r\n canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.droid_1), 10, 10, null);\r\n}\r\n<\/pre>\n<p>The <strong><i>drawBitmap<\/i><\/strong> method draws the <strong><i>droid_1<\/i><\/strong> image to the coordinates 10,10.<br \/>\nWe obtain the bitmap from the application resources by passing the id of our image (resource), which is <strong><i>droid_1<\/i><\/strong> in our case. When we copied the <strong><i>droid_1.png<\/i><\/strong> into the resource directory eclipse detected it and the plugin executed the necessary scripts in the background so we have the <strong><i>droid_1<\/i><\/strong> identifier in the <strong><i>R.java<\/i><\/strong> file. The R.java holds the resource identifiers.<\/p>\n<p>The thread suffered some changes too. Examine the new <strong><i>run()<\/i><\/strong> method.<\/p>\n<pre class=\"brush:java\">public void run() {\r\n  Canvas canvas;\r\n  Log.d(TAG, \"Starting game loop\");\r\n  while (running) {\r\n   canvas = null;\r\n   \/\/ try locking the canvas for exclusive pixel editing on the surface\r\n   try {\r\n    canvas = this.surfaceHolder.lockCanvas();\r\n    synchronized (surfaceHolder) {\r\n     \/\/ update game state\r\n     \/\/ draws the canvas on the panel\r\n     this.gamePanel.onDraw(canvas);\r\n    }\r\n   } finally {\r\n    \/\/ in case of an exception the surface is not left in\r\n    \/\/ an inconsistent state\r\n    if (canvas != null) {\r\n     surfaceHolder.unlockCanvasAndPost(canvas);\r\n    }\r\n   } \/\/ end finally\r\n  }\r\n }\r\n<\/pre>\n<p>In line <strong>02<\/strong> we declare the canvas on which we will draw our image. The canvas is the surface\u2019s bitmap onto which we can draw and we can edit its pixels. In line <strong>08<\/strong> we try to get hold of it and in line <strong>12<\/strong> we trigger the panel\u2019s <strong><i>onDraw<\/i><\/strong> event to which we pass the obtained canvas. Note that it is a synchronised block which means that we have exclusivity on it and nothing can modify it while we are using it.<br \/>\nThe functionality is very simple and basic. On every execution of the game loop we get hold of the canvas and we pass it to the game panel to draw on it. The game panel just displays the image at coordinates 10,10. Now back to the FPS. If the number of times per second the image is displayed drops below 20, it starts to get noticeable by us humans. The challenge is to keep this rate above a set level and we will see how shortly.<\/p>\n<p>Try running the code and you should see our droid displayed close to the top left corner.<\/p>\n<table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"tr-caption-container\" style=\"margin-left: auto;margin-right: auto;text-align: center\">\n<tbody>\n<tr>\n<td style=\"text-align: center\"><a href=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/08\/Screen-shot-2010-08-15-at-18.52.12.png\"><img decoding=\"async\" border=\"0\" height=\"139\" src=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/08\/Screen-shot-2010-08-15-at-18.52.12.png\" width=\"320\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\" style=\"text-align: center\">Droid in top left corner<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong><span class=\"Apple-style-span\" style=\"font-size: large\">Moving the Image<\/span><\/strong><\/p>\n<p>Now that we have displayed it, let\u2019s try moving it. How? We will use our finger. We will implement a simple drag and drop functionality. To pick up an image we will simply touch it and while our finger is on the screen we will update the image\u2019s coordinates accordingly. Once the touch is finished we leave the image there where the last touch was recorded.<\/p>\n<p>We need to create an object that will hold our image and the coordinates.<br \/>\nI have created <strong><i>Droid.java<\/i><\/strong> for this. Note that I have put the class into the <strong><i>net.obviam.droidz.model<\/i><\/strong> package.<\/p>\n<pre class=\"brush:java\">package net.obviam.droidz.model;\r\n\r\nimport android.graphics.Bitmap;\r\n\r\npublic class Droid {\r\n\r\n private Bitmap bitmap; \/\/ the actual bitmap\r\n private int x;   \/\/ the X coordinate\r\n private int y;   \/\/ the Y coordinate\r\n\r\n public Droid(Bitmap bitmap, int x, int y) {\r\n  this.bitmap = bitmap;\r\n  this.x = x;\r\n  this.y = y;\r\n }\r\n\r\n public Bitmap getBitmap() {\r\n  return bitmap;\r\n }\r\n public void setBitmap(Bitmap bitmap) {\r\n  this.bitmap = bitmap;\r\n }\r\n public int getX() {\r\n  return x;\r\n }\r\n public void setX(int x) {\r\n  this.x = x;\r\n }\r\n public int getY() {\r\n  return y;\r\n }\r\n public void setY(int y) {\r\n  this.y = y;\r\n }\r\n}\r\n<\/pre>\n<p>It is a plain class with some attributes and a constructor.<br \/>\nThe <strong>x<\/strong> and <strong>y<\/strong> are the coordinates of the droid. The bitmap holds the image that will be displayed as the droid. It is the graphical representation of it.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>So far nothing special. But to play around with it we need to add some state. To keep it simple, the droid has only 2 states. <i>Touched<\/i> and <i>untouched<\/i>. By <i>touched<\/i> I mean when our finger touched the droid on the screen. We keep the touched state <i>true<\/i> while we hold our finger down on the screen at the droid\u2019s position. Otherwise the droid remains untouched (state set to <i>false<\/i>).<\/p>\n<p>Check out the new droid class.<\/p>\n<pre class=\"brush:java\">package net.obviam.droidz.model;\r\n\r\nimport android.graphics.Bitmap;\r\nimport android.graphics.Canvas;\r\nimport android.view.MotionEvent;\r\n\r\npublic class Droid {\r\n\r\n private Bitmap bitmap; \/\/ the actual bitmap\r\n private int x;   \/\/ the X coordinate\r\n private int y;   \/\/ the Y coordinate\r\n private boolean touched; \/\/ if droid is touched\/picked up\r\n\r\n public Droid(Bitmap bitmap, int x, int y) {\r\n  this.bitmap = bitmap;\r\n  this.x = x;\r\n  this.y = y;\r\n }\r\n\r\n public Bitmap getBitmap() {\r\n  return bitmap;\r\n }\r\n public void setBitmap(Bitmap bitmap) {\r\n  this.bitmap = bitmap;\r\n }\r\n public int getX() {\r\n  return x;\r\n }\r\n public void setX(int x) {\r\n  this.x = x;\r\n }\r\n public int getY() {\r\n  return y;\r\n }\r\n public void setY(int y) {\r\n  this.y = y;\r\n }\r\n\r\n public boolean isTouched() {\r\n  return touched;\r\n }\r\n\r\n public void setTouched(boolean touched) {\r\n  this.touched = touched;\r\n }\r\n\r\n public void draw(Canvas canvas) {\r\n  canvas.drawBitmap(bitmap, x - (bitmap.getWidth() \/ 2), y - (bitmap.getHeight() \/ 2), null);\r\n }\r\n\r\n public void handleActionDown(int eventX, int eventY) {\r\n  if (eventX &gt;= (x - bitmap.getWidth() \/ 2) &amp;&amp; (eventX &lt;= (x + bitmap.getWidth()\/2))) {\r\n   if (eventY &gt;= (y - bitmap.getHeight() \/ 2) &amp;&amp; (y &lt;= (y + bitmap.getHeight() \/ 2))) {\r\n    \/\/ droid touched\r\n    setTouched(true);\r\n   } else {\r\n    setTouched(false);\r\n   }\r\n  } else {\r\n   setTouched(false);\r\n  }\r\n\r\n }\r\n}\r\n<\/pre>\n<p>We added the <strong><i>touched<\/i><\/strong> field to keep track of the state of our droid. You will notice two more methods: <strong><i>public void draw(Canvas canvas)<\/i><\/strong> and <strong><i>public void handleActionDown(int eventX, int eventY)<\/i><\/strong>.<br \/>\nThese methods are discussed later.<br \/>\nNow let\u2019s have a look at the <strong><i>MainGamePanel.java<\/i><\/strong>. It changed quite a lot.<\/p>\n<pre class=\"brush:java\">package net.obviam.droidz;\r\n\r\nimport net.obviam.droidz.model.Droid;\r\nimport android.app.Activity;\r\nimport android.content.Context;\r\nimport android.graphics.BitmapFactory;\r\nimport android.graphics.Canvas;\r\nimport android.graphics.Color;\r\nimport android.util.Log;\r\nimport android.view.MotionEvent;\r\nimport android.view.SurfaceHolder;\r\nimport android.view.SurfaceView;\r\n\r\npublic class MainGamePanel extends SurfaceView implements\r\n  SurfaceHolder.Callback {\r\n\r\n private static final String TAG = MainGamePanel.class.getSimpleName();\r\n\r\n private MainThread thread;\r\n private Droid droid;\r\n\r\n public MainGamePanel(Context context) {\r\n  super(context);\r\n  \/\/ adding the callback (this) to the surface holder to intercept events\r\n  getHolder().addCallback(this);\r\n\r\n  \/\/ create droid and load bitmap\r\n  droid = new Droid(BitmapFactory.decodeResource(getResources(), R.drawable.droid_1), 50, 50);\r\n\r\n  \/\/ create the game loop thread\r\n  thread = new MainThread(getHolder(), this);\r\n\r\n  \/\/ make the GamePanel focusable so it can handle events\r\n  setFocusable(true);\r\n }\r\n\r\n @Override\r\n public void surfaceChanged(SurfaceHolder holder, int format, int width,\r\n   int height) {\r\n }\r\n\r\n @Override\r\n public void surfaceCreated(SurfaceHolder holder) {\r\n  \/\/ at this point the surface is created and\r\n  \/\/ we can safely start the game loop\r\n  thread.setRunning(true);\r\n  thread.start();\r\n }\r\n\r\n @Override\r\n public void surfaceDestroyed(SurfaceHolder holder) {\r\n  Log.d(TAG, \"Surface is being destroyed\");\r\n  \/\/ tell the thread to shut down and wait for it to finish\r\n  \/\/ this is a clean shutdown\r\n  boolean retry = true;\r\n  while (retry) {\r\n   try {\r\n    thread.join();\r\n    retry = false;\r\n   } catch (InterruptedException e) {\r\n    \/\/ try again shutting down the thread\r\n   }\r\n  }\r\n  Log.d(TAG, \"Thread was shut down cleanly\");\r\n }\r\n\r\n @Override\r\n public boolean onTouchEvent(MotionEvent event) {\r\n  if (event.getAction() == MotionEvent.ACTION_DOWN) {\r\n   \/\/ delegating event handling to the droid\r\n   droid.handleActionDown((int)event.getX(), (int)event.getY());\r\n\r\n   \/\/ check if in the lower part of the screen we exit\r\n   if (event.getY() &gt; getHeight() - 50) {\r\n    thread.setRunning(false);\r\n    ((Activity)getContext()).finish();\r\n   } else {\r\n    Log.d(TAG, \"Coords: x=\" + event.getX() + \",y=\" + event.getY());\r\n   }\r\n  } if (event.getAction() == MotionEvent.ACTION_MOVE) {\r\n   \/\/ the gestures\r\n   if (droid.isTouched()) {\r\n    \/\/ the droid was picked up and is being dragged\r\n    droid.setX((int)event.getX());\r\n    droid.setY((int)event.getY());\r\n   }\r\n  } if (event.getAction() == MotionEvent.ACTION_UP) {\r\n   \/\/ touch was released\r\n   if (droid.isTouched()) {\r\n    droid.setTouched(false);\r\n   }\r\n  }\r\n  return true;\r\n }\r\n\r\n @Override\r\n protected void onDraw(Canvas canvas) {\r\n  \/\/ fills the canvas with black\r\n  canvas.drawColor(Color.BLACK);\r\n  droid.draw(canvas);\r\n }\r\n}\r\n<\/pre>\n<p>Line <strong>28<\/strong> creates the <strong>droid<\/strong> object at the the coordinates <i>50,50<\/i>.<br \/>\nIt is declared as an attribute in line <strong>20<\/strong>.<\/p>\n<p>In the <strong><i>onTouchEvent<\/i><\/strong> (method line <strong>71<\/strong>) if the action is the touch of the screen (<strong><i>MotionEvent.ACTION_DOWN<\/i><\/strong>) we want to know if our finger landed on the droid. To do this is easy. We need to check if the event\u2019s coordinates are inside the droid\u2019s bitmap. In order not to clutter the <strong><i>onTouch<\/i><\/strong> event we just delegate this to the droid object. Now you can go back to the <strong><i>Droid.java<\/i><\/strong> class and check the <strong><i>handleActionDown<\/i><\/strong> method.<\/p>\n<pre class=\"brush:java\">public void handleActionDown(int eventX, int eventY) {\r\n  if (eventX &gt;= (x - bitmap.getWidth() \/ 2) &amp;&amp; (eventX &lt;= (x + bitmap.getWidth()\/2))) {\r\n   if (eventY &gt;= (y - bitmap.getHeight() \/ 2) &amp;&amp; (y &lt;= (y + bitmap.getHeight() \/ 2))) {\r\n    \/\/ droid touched\r\n    setTouched(true);\r\n   } else {\r\n    setTouched(false);\r\n   }\r\n  } else {\r\n   setTouched(false);\r\n  }\r\n\r\n }\r\n<\/pre>\n<p>It is very simple. If the action happened inside the area of our droid\u2019s bitmap we\u2019ll set its touched status to <strong>true<\/strong><\/p>\n<p>Going back to the <strong><i>onTouched<\/i><\/strong> method, notice that there is a code block (lines <strong>81<\/strong>&#8211;<strong>86<\/strong>) that is executed when the event is of type <strong><i>MotionEvent.ACTION_MOVE<\/i><\/strong>. This event happens when our finger started to move on the screen. It is simple. We check if the droid is <strong><i>touched<\/i><\/strong> and if so we just update its coordinates accordingly.<br \/>\nThat is it. This was the update game state. We have updated the state of our sole object in the game. The touched state and the coordinates. Now it is time to display it.<\/p>\n<p>Check the <strong><i>onDraw<\/i><\/strong> method. This is triggered at every execution of the main loop inside the thread remember?<br \/>\nIt contains 2 lines. Line <strong>99<\/strong> simply fills the canvas with black and line <strong>100<\/strong> tells the droid to draw itself on the canvas provided. By doing this is like me giving you a paper to draw yourself onto it, and give the paper back to me so I can continue my drawing.<\/p>\n<p>Check <strong><i>Droid.java<\/i><\/strong> for the draw implementation. It is dead simple. It takes the bitmap it was instantiated with and draws it to the canvas at the coordinates the droid is at in that moment. Note that the coordinates of the droid are exactly in the center of the bitmap so we need to move the pointer to the top left corner of the image and draw it there. I\u2019m sure you won\u2019t find it hard to understand.<\/p>\n<p>That\u2019s it. Run it and have a play with it.<\/p>\n<p>Download he code for the project <a href=\"http:\/\/obviam.net\/source_code\/droidz.android.02.3-graphics.tar.gz\">here (droidz.android.02.3-graphics.tar.gz)<\/a><\/p>\n<p><strong>Reference:<\/strong>&nbsp;<a href=\"http:\/\/obviam.net\/index.php\/displaying-graphics-with-android\/\">Displaying Images with Android<\/a>&nbsp;from our&nbsp;<a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG<\/a>&nbsp;partner Tamas Jano&nbsp;from &#8220;<a href=\"http:\/\/obviam.net\/\">Against The Grain<\/a>&#8221; blog.<\/p>\n<div style=\"margin: 0px\">Do not forget to check out our new <strong><i>Android Game<\/i><\/strong> <strong><i><a href=\"http:\/\/www.javacodegeeks.com\/2011\/06\/jcg-studios-arkdroid-official-launch.html\">ArkDroid<\/a>&nbsp;<span class=\"Apple-style-span\" style=\"font-weight: normal\"><span class=\"Apple-style-span\" style=\"font-style: normal\">(screenshots below)<\/span><\/span><\/i><\/strong>. You feedback will be more than helpful!<\/div>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/4.bp.blogspot.com\/-v5rXlea2AAc\/ThBFnQcGXzI\/AAAAAAAAABc\/1g9QLfejC5U\/s1600\/multiple.jpg\"><img decoding=\"async\" border=\"0\" height=\"200\" src=\"http:\/\/4.bp.blogspot.com\/-v5rXlea2AAc\/ThBFnQcGXzI\/AAAAAAAAABc\/1g9QLfejC5U\/s200\/multiple.jpg\" width=\"133\" \/><\/a><a href=\"http:\/\/1.bp.blogspot.com\/-0dr410FpxAA\/TgdJc44bfvI\/AAAAAAAAADg\/GyMLvayT_rc\/s1600\/arkdroid_ingame.jpg\"><img decoding=\"async\" border=\"0\" height=\"200\" src=\"http:\/\/1.bp.blogspot.com\/-0dr410FpxAA\/TgdJc44bfvI\/AAAAAAAAADg\/GyMLvayT_rc\/s200\/arkdroid_ingame.jpg\" width=\"133\" \/><\/a><a href=\"http:\/\/1.bp.blogspot.com\/-sEqMxR7YZnY\/ThBGdHcIYnI\/AAAAAAAAABs\/S6iKs2lycyk\/s1600\/multiple_sticky.jpg\"><img decoding=\"async\" border=\"0\" height=\"200\" src=\"http:\/\/1.bp.blogspot.com\/-sEqMxR7YZnY\/ThBGdHcIYnI\/AAAAAAAAABs\/S6iKs2lycyk\/s200\/multiple_sticky.jpg\" style=\"cursor: move\" width=\"133\" \/><\/a><\/div>\n<div style=\"margin: 0px\"><strong>Related Articles:<\/strong><\/div>\n<ul style=\"text-align: left\">\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/06\/android-game-development-tutorials.html\">Android Game Development Tutorials Introduction<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-game-idea.html\">Android Game Development &#8211; The Game Idea<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-create-project.html\">Android Game Development &#8211; Create The Project<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-basic-game.html\">Android Game Development &#8211; A Basic Game Architecture<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-basic-game_05.html\">Android Game Development &#8211; A Basic Game Loop<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-moving-images.html\">Android Game Development &#8211; Moving Images on Screen<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-game-loop.html\">Android Game Development &#8211; The Game Loop<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-measuring-fps.html\">Android Game Development &#8211; Measuring FPS<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html\">Android Game Development &#8211; Sprite Animation<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/08\/android-game-development-particle.html\">Android Game Development &#8211; Particle Explosion<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/08\/android-game-development-design-in-game.html\">Android Game Development &#8211; Design In-game Entities &#8211; The Strategy Pattern<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/android-game-development-using-bitmap.html\">Android Game Development &#8211; Using Bitmap Fonts<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/android-game-development-switching-from.html\">Android Game Development &#8211; Switching from Canvas to OpenGL ES<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html\">Android Game Development \u2013 Displaying Graphical Elements (Primitives) with OpenGL ES<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-opengl-texture.html\">Android Game Development \u2013 OpenGL Texture Mapping<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-design-in-game.html\">Android Game Development \u2013 Design In-game Entities \u2013 The State Pattern<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/?tag=android-games\">Android Games Article Series<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Before moving to the actual game loop let\u2019s display some graphics so we can get some measurements done. If you haven\u2019t checked it out please do as it is imperative that you understand how a thread updates the screen. You can check it out here. Displaying an image using Android is extremely simple. To scale &hellip;<\/p>\n","protected":false},"author":27,"featured_media":46,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-479","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android-games"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Android Game Development - Displaying Images with Android - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Before moving to the actual game loop let\u2019s display some graphics so we can get some measurements done. If you haven\u2019t checked it out please do as it is\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android Game Development - Displaying Images with Android - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Before moving to the actual game loop let\u2019s display some graphics so we can get some measurements done. If you haven\u2019t checked it out please do as it is\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2011-07-07T23:02:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T20:01:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Impaler\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Impaler\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-displaying.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-displaying.html\"},\"author\":{\"name\":\"Impaler\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/6bad1a2db4fb0129703629617c049f8c\"},\"headline\":\"Android Game Development &#8211; Displaying Images with Android\",\"datePublished\":\"2011-07-07T23:02:00+00:00\",\"dateModified\":\"2012-10-21T20:01:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-displaying.html\"},\"wordCount\":1278,\"commentCount\":28,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-displaying.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"articleSection\":[\"Android Games\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-displaying.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-displaying.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-displaying.html\",\"name\":\"Android Game Development - Displaying Images with Android - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-displaying.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-displaying.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"datePublished\":\"2011-07-07T23:02:00+00:00\",\"dateModified\":\"2012-10-21T20:01:33+00:00\",\"description\":\"Before moving to the actual game loop let\u2019s display some graphics so we can get some measurements done. If you haven\u2019t checked it out please do as it is\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-displaying.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-displaying.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-displaying.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-displaying.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/android\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Android Games\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/android\\\/android-games\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Android Game Development &#8211; Displaying Images with Android\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/6bad1a2db4fb0129703629617c049f8c\",\"name\":\"Impaler\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g\",\"caption\":\"Impaler\"},\"sameAs\":[\"http:\\\/\\\/obviam.net\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Impaler\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android Game Development - Displaying Images with Android - Java Code Geeks","description":"Before moving to the actual game loop let\u2019s display some graphics so we can get some measurements done. If you haven\u2019t checked it out please do as it is","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html","og_locale":"en_US","og_type":"article","og_title":"Android Game Development - Displaying Images with Android - Java Code Geeks","og_description":"Before moving to the actual game loop let\u2019s display some graphics so we can get some measurements done. If you haven\u2019t checked it out please do as it is","og_url":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2011-07-07T23:02:00+00:00","article_modified_time":"2012-10-21T20:01:33+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","type":"image\/jpeg"}],"author":"Impaler","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Impaler","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html"},"author":{"name":"Impaler","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/6bad1a2db4fb0129703629617c049f8c"},"headline":"Android Game Development &#8211; Displaying Images with Android","datePublished":"2011-07-07T23:02:00+00:00","dateModified":"2012-10-21T20:01:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html"},"wordCount":1278,"commentCount":28,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","articleSection":["Android Games"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html","url":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html","name":"Android Game Development - Displaying Images with Android - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","datePublished":"2011-07-07T23:02:00+00:00","dateModified":"2012-10-21T20:01:33+00:00","description":"Before moving to the actual game loop let\u2019s display some graphics so we can get some measurements done. If you haven\u2019t checked it out please do as it is","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Android","item":"https:\/\/www.javacodegeeks.com\/category\/android"},{"@type":"ListItem","position":3,"name":"Android Games","item":"https:\/\/www.javacodegeeks.com\/category\/android\/android-games"},{"@type":"ListItem","position":4,"name":"Android Game Development &#8211; Displaying Images with Android"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/6bad1a2db4fb0129703629617c049f8c","name":"Impaler","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g","caption":"Impaler"},"sameAs":["http:\/\/obviam.net\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Impaler"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=479"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/479\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/46"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}