Tuesday, March 22, 2011

[android-developers] Why can't draw a picture on canvas

Following is my test code

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

Canvas canvas = new Canvas();
Drawable draw = getResources().getDrawable(R.drawable.bg);

Bitmap bitmap = Bitmap.createBitmap(draw.getIntrinsicWidth(),
draw.getIntrinsicWidth(),
Bitmap.Config.RGB_565);
Paint paint = new Paint();
paint.setColor(30);
canvas.setBitmap(bitmap);
canvas.drawBitmap(bitmap, bitmap.getHeight(), bitmap.getWidth(), paint);
}

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

No comments:

Post a Comment