由网友(捂着心说:不疼)分享简介:我有一个观点。我希望把位图图像作为背景图像。我没能做到这一点。I have a view. I want to place a bitmap image as its background image. I was not able to do that.//My code is belowBitmap bitma...
我有一个观点。我希望把位图图像作为背景图像。我没能做到这一点。
I have a view. I want to place a bitmap image as its background image. I was not able to do that.
//My code is below
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.grape);
part1 = new View(this);
Bitmap map2 = Bitmap.createBitmap(targetWidth, targetHeight,Bitmap.Config.ARGB_8888);
canvas.drawBitmap( bitmapOrg,new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()), new Rect(0, 0, targetWidth, targetHeight), null);
part1.setBackgroundResource(map2); //i couldn't place map2 as bgresource to my view part1
谁能帮助?
推荐答案
根据API文档,setBackgroundResource预计一个int。
According to the API docs, setBackgroundResource
expects an int.
如果你肯定需要一个位图,你可以使用setBackgroundDrawable反而,敷在BitmapDrawable.
If you definitely need a bitmap, you can use setBackgroundDrawable
instead and wrap your bitmap in a BitmapDrawable
.
相关推荐
最新文章