开发者

Android: how to simply draw a bitmap on another bitmap

开发者 https://www.devze.com 2023-02-07 04:04 出处:网络
I\'m new to Android dev and I\'m having a hard time trying to do something which seems obvious to me: drawing little images on top of a bigger开发者_StackOverflow社区 image.

I'm new to Android dev and I'm having a hard time trying to do something which seems obvious to me: drawing little images on top of a bigger开发者_StackOverflow社区 image.

Let's say that I have a 500x500 image and I want to draw icons at different locations. Icons are png files that I load with:

Bitmap img = BitmapFactory.decodeResource(getResources(), R.drawable.idIcon1)

My "background image" is a LayerDrawable.

Then, I am totally lost... Do I have to create a canvas ? How to draw on my "background image" my icons at different positions?


int positionLeft=0;
int positionTop=0;
Bitmap newBitmap =Bitmap.createBitmap(backgroundBitmap.getWidth(),bitmap.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(newBitmap);
canvas.drawBitmap(backgroundBitmap, positionLeft, positionTop,null);
positionLeft=100;
positionTop=100;         
canvas.drawBitmap(iconBitmap,positionLeft,positionTop,null);
imageView.setImageBitmap(newBitmap);


You're making simple things difficult. Just use a layout with android:background attribute, and then add ImageViews dynamically with the necessary bitmaps inside.

0

精彩评论

暂无评论...
验证码 换一张
取 消