例如 ..
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);
像上面这样可行吗?
最佳答案
你真的不应该那样做。我的建议是这样做
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
传递给可绘制对象作为背景。如果您确实想将
Bitmap
设置为来源,则应制作一个ImageView