Hello World Using an Image

In this section, you are going to use the Hello World! application to get more familiar with a relatively common practice in programming: displaying images. Modern computer displays would be exceedingly uninteresting without a graphical display. These graphical displays center on the ability to send images to the screen.

Emulator. The following illustration depicts the results of your Hello World! application.

As late as five years ago, displaying images was a fairly difficult thing to do on a cell phone. Working with images is just one of those things that we, as modern PC users, take for granted. We look at windows of all types everyday without even considering that they are really images sent to a screen. This version of the Hello World! application will display an image to the screen that says "Hello World!"

For this application, use the New Android Project wizard to create a new project and name it HelloWorldImage, as shown in the following illustration.

With the application project created, navigate to and remove the TextView code from main.xml so that you have a clean project. If you do not remove this code, you will end up with a text-based Hello World! program again.

Before you begin writing any code, you need an image to display. Create a small image in the graphics program of your choice. For ease of use, I chose Microsoft Paint, but any program should be able to give you the desired image. The image I am using is shown here:

Hello I /Tfe World J

Name your image helloworld.png and save it to the %workspace%/HelloWorldImage/ res/drawable directory.

0 0

Post a comment