Android Pixmap Pixels for the People

According to the design of our Pixmap interface from Chapter 3, there's not much to implement. Listing 5-12 shows the code.

Listing 5-12., a Pixmap Implementation Wrapping a Bitmap package com.badlogic.androidgames.framework.impl;


import com.badlogic.androidgames.framework.Graphics.PixmapFormat; import com.badlogic.androidgames.framework.Pixmap;

public class AndroidPixmap implements Pixmap { Bitmap bitmap; PixmapFormat format;

public AndroidPixmap(Bitmap bitmap, PixmapFormat format) { this.bitmap = bitmap;

this.format = format;

^Override public int getWidth() {

return bitmap.getWidth();

^Override public int getHeight() {

return bitmap.getHeight();

^Override public PixmapFormat getFormat() { return format;

^Override public void dispose() { bitmap.recycle();

All we do is store the Bitmap instance that we wrap, along with its format, which is stored as a PixmapFormat enumeration value, as defined in Chapter 3. Additionally we implement the required methods of the Pixmap interface so we can query the width and height of the Pixmap and its format, and also ensure that the pixels can get dumped from RAM. Note that the bitmap member is package private, so we can access it in AndroidGraphics, which we'll implement now.

0 0

Post a comment