Game Development Reference
In-Depth Information
renders the video on the device (see Listing 7-6). To create a 32-bit ARGB bitmap in Android, you use the
following call:
Bitmap.createBitmap(width, height, Config.ARGB_8888)
Config.ARGB_8888 tells the system you wish to use a 4-byte (32-bit) ARGB bitmap. You will use this
bitmap to set pixels for the video in later sections. Note that this callback fires only once during the
lifetime of the game. To set the width and height of the video buffer ImageView , use a call to
ImageView.getLayoutParams() .
Listing 7-6. Graphics Initialization
public void OnInitGraphics(int w, int h) {
Log.d(TAG, "OnInitGraphics creating Bitmap of " + w + " by " + h);
mBitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888);
LayoutParams lp = mView.getLayoutParams();
mWidth = w;
mHeight = h;
lp.width = w;
lp.height = h;
}
Image Update Handler
The image update handler receives an array of ARGB packed pixels representing a color (see Listing 7-7).
It fires multiple times per second, and its job is to replace pixels in the bitmap with the colors in the array
by calling the following method:
mBitmap.setPixels(pixels, offset, stride, x, y, width, height)
Here, the arguments are as follows:
pixels is the colors to write to the bitmap.
offset is the index of the first color to read from pixels[] .
stride is the number of colors in pixels[] to skip between rows (normally, this
value will be the same as the width of the bitmap.
x is the x coordinate of the first pixel to write to in the bitmap.
y is the y coordinate of the first pixel to write to in the bitmap.
width is the number of colors to copy from pixels[] per row.
height is the number of rows to write to the bitmap.
Listing 7-7. Image Update Handler
public void OnImageUpdate(int[] pixels) {
mBitmap.setPixels(pixels, 0, mWidth, 0, 0, mWidth, mHeight);
Search WWH ::




Custom Search