public class PictureView extends View
{
public PictureView(Context context)
{
super(context);
}
Resources r = this.getContext().getResources();
InputStream is = r.openRawResource(R.drawable.tree);
BitmapDrawable bmpDraw = new BitmapDrawable(is);
Bitmap tree = bmpDraw.getBitmap();
int length=tree.getWidth();
int height=tree.getHeight();
Paint paint;
public void onDraw(Canvas canvas)
{
Bitmap[] bitmap=new Bitmap[9];
Bitmap[] bitmapTransfer=new Bitmap[3];
for(int i=0;i<3;i++)
{
bitmapTransfer[i]=Bitmap.createBitmap(tree, 0, i*height/3,length,height/3);
for(int j=0;j<3;j++)
{
bitmap[i*3+j]=Bitmap.createBitmap(bitmapTransfer[i], j*length/3,0,length/3,height);
}
}
canvas.drawBitmap(bitmap[0], 70, 100, paint);
}
}
这是自定义的View,activity的代码就是显示这个view
这一段代码,在运行安卓的时候,程序直接报错,请问哪里有错?应该怎么改?
把错误的LOGCAT贴出来,要根据错误信息看啊!
05-15 15:23:23.001: E/AndroidRuntime(360): java.lang.IllegalArgumentException: y + height must be <= bitmap.height()
我看主要是这条