Game Development Reference
In-Depth Information
protected void
onDraw(Canvas canvas) {
canvas.drawRGB(0, 0, 0);
dst.set(50, 50, 350, 350);
canvas.drawBitmap(bob565,
null
, dst,
null
);
canvas.drawBitmap(bob4444, 100, 100,
null
);
invalidate();
}
}
@Override
public void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
requestWindowFeature(Window.
FEATURE_NO_TITLE
);
getWindow().setFlags(WindowManager.LayoutParams.
FLAG_FULLSCREEN
,
WindowManager.LayoutParams.
FLAG_FULLSCREEN
);
setContentView(
new
RenderView(
this
));
}
}
The
onCreate()
method of our activity is old hat, so let's move on to our custom
View
. It has two
Bitmap
members, one storing an image of Bob (introduced in Chapter 3) in RGB565 format, and
another storing an image of Bob in ARGB4444 format. We also have a
Rect
member, where we
store the destination rectangle for rendering.
In the constructor of the
RenderView
class, we first load Bob into the
bob565
member of the
View
. Note that the image is loaded from an RGB888 PNG file, and that the
BitmapFactory
will
automatically convert this to an RGB565 image. To prove this, we also output the
Bitmap.Config
of the
Bitmap
to LogCat. The RGB888 version of Bob has an opaque white background, so no
blending needs to be performed.
Next we load Bob from an ARGB8888 PNG file stored in the
assets/
directory. To save some
memory, we also tell the
BitmapFactory
to convert this image of Bob to an ARGB4444 bitmap.
The factory may not obey this request (for unknown reasons). To see whether it was nice to us,
we output the
Bitmap.Config
file of this
Bitmap
to LogCat as well.
The
onDraw()
method is puny. All we do is fill the screen with black, draw
bob565
scaled to
250×250 pixels (from his original size of 160×183 pixels), and draw
bob4444
on top of
bob565
,
unscaled but blended (which is done automagically by the
Canvas
). Figure
4-14
shows the two
Bobs in all their glory.