2011/3/22 Nicholas Johnson <[email protected]>:
> It appears, by your code, that you are drawing on the bitmap through the
> canvas. However, I'm guessing your real question is: why is my bitmap not
> being displayed on the screen? Well, that's because your bitmap or canvas is
> not associated at all with any buffers which finally get displayed on your
> device.
> Here are 2 options for you:
> 1) If you're just trying to display a picture to the screen that doesn't
> change, then just put an ImageView in your view hierarchy and define the
> "android:src="R.drawable.bg"".
> 2) If you're end goal is to do custom drawing onto the screen, then you're
> going to have to create a custom view and override the onDraw method, which
> gives you the Canvas object which is "linked" to the display.
> Remember, a Canvas is just a tool for drawing onto a bitmap. It
> has, inherently, nothing to do with drawing something to the screen.
> Nick

yes, a rewrite my test code following your 2th point. It can draw a bitmap now.
It should "linked" to the gaven canvas.

public class testCanvas extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        try{
            super.onCreate(savedInstanceState);
            myView myview = new myView(this);
            setContentView(myview);
//            setContentView(R.layout.main);


        }catch(Exception e) {
            e.printStackTrace();
        }
    }

    private  class myView extends View {
        public myView(Context context) {
            super(context);
        }

        @Override
        protected void onDraw(Canvas canvas) {

            Drawable draw = getResources().getDrawable(R.drawable.bg);
            Bitmap bitmap =
BitmapFactory.decodeResource(this.getResources(), R.drawable.bg);
            Paint paint = new Paint();
            paint.setColor(Color.BLUE);
            canvas.drawColor(Color.WHITE);
//            canvas.setBitmap(bitmap);
            canvas.drawBitmap(bitmap, 50, 60, paint);
            canvas.drawText("harvey", 160, 240, paint);
        }
    }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to