Hi,
I am using the code below to attempt to display a bitmap, which will
act as the splash screen for a little android pacman game im creating
(learning may aswell be fun). The problem is that the JPG file is not
being displayed. I can see no reason why this is happening.

I've done a toString in the Log for mPacManMenImg, so it seems like
the following line:
   mPacManMenuImg = BitmapFactory.decodeResource(res,
R.drawable.pacman_thumb);
is correctly returning a reference to the Bitmap.

I have checked and the image is listed as pacman_thumb in drawable, on
R.java.

Any ideas? (code follows)
Thanks

package android.pacman.com;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.widget.RelativeLayout;
public class PacMan extends Activity {

 private PacManView mMenuView;

    @Override
    public void onCreate(Bundle savedInstanceState) {

      /* have to run the constructor */
     super.onCreate(savedInstanceState);

     /* set the view to the paclayout view */
     setContentView(R.layout.paclayout);

     /* get a reference to the paclayout view */
     mMenuView = (PacManView) findViewById(R.id.pacman_surface);


    }
}




package android.pacman.com;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class PacManView extends SurfaceView implements
SurfaceHolder.Callback {
 private Resources res;
 private Bitmap mPacManMenuImg;
 private SurfaceHolder mSurfaceHolder;
 private Canvas c;

 public PacManView (Context context, AttributeSet attrs) {
  super(context, attrs);

  // register our interest in hearing about changes to our surface
  mSurfaceHolder = getHolder();
  mSurfaceHolder.addCallback(this);

        setFocusable(true); // make sure we get key events

        /* get our resources */
        res = context.getResources();
 }


 /* Callback invoked when the surface dimensions change. */
    public void surfaceChanged(SurfaceHolder holder, int format, int
width, int height) {
     Log.w("SurfaceChanged","got here");

     //load background image as a Bitmap instead of a Drawable b/c
        // we don't need to transform it and it's faster to draw this
way
        mPacManMenuImg = BitmapFactory.decodeResource(res,
R.drawable.pacman_thumb);

        mPacManMenuImg = Bitmap.createScaledBitmap(mPacManMenuImg, 0,
0, true);


     c = mSurfaceHolder.lockCanvas(null);
        c.drawBitmap(mPacManMenuImg, 0, 0, null);

    }

    public void surfaceCreated(SurfaceHolder holder) {

    }

    /*
     * Callback invoked when the Surface has been destroyed and must
no longer
     * be touched. WARNING: after this method returns, the Surface/
Canvas must
     * never be touched again!
     */
    public void surfaceDestroyed(SurfaceHolder holder) {
     Log.w("SurfaceDestroyed","got here");
    }

}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to