例如......
Bitmap myPic = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
Bitmap newPic = Bitmap.createScaledBitmap(myPic, 50, 50, true);
Canvas myCanv = new Canvas(newPic);
View myView = (View)findViewById(R.id.view1);
myView.draw(myCanv);
就像上面那样可行吗?
答案 0 :(得分:1)
你真的不应该这样做。我的建议是这样做
Bitmap myPic = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
myPic = Bitmap.createScaledBitmap(myPic,50,50, true);
BitmapDrawable draw = new BitmapDrawable(this.getResources(), myPic);
View myView = (View) findViewById (R.id.view1);
myView.setBackground(draw);
这样您就可以将View
一个drawable作为背景传递。
如果您确实想要设置Bitmap
作为来源,那么您应该制作ImageView