安卓:来自另一个资源的绘制位图 [英] Android: Draw bitmap from resources over another
问题描述
我有两个位图,的背景和前景的。如何绘制位图前景的背景,而不使用其他印刷品吗?
I have got two bitmaps, background and foreground. How to draw bitmap foreground on background without using another Canvas?
=========编辑==========
========= EDIT ==========
1)首先创建位图资源使用附加选项ARGB_8888
1) First create bitmaps from resources with additional option ARGB_8888
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
2)声明位图
2) Declare bitmaps
Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.background, options);
Bitmap foreground = BitmapFactory.decodeResource(getResources(), R.drawable.foreground, options);
3)内部的OnDraw()函数绘制图形
3) Inside onDraw() function draw graphics
protected void onDraw(Canvas canvas)
{
canvas.drawColor(Color.White);
Paint paint = new Paint();
canvas.drawBitmap(background, 0, 0, paint);
paint.setXfermode( new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
canvas.drawBitmap(foreground, 0, 0, paint);
}
和作为Soxxeh说,这是信息的非常好的来源:<一href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Xfermodes.html" rel="nofollow">http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Xfermodes.html
And as Soxxeh said, this is very good source of information: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Xfermodes.html
推荐答案
试试这个:
canvas.drawBitmap(backgroundImageBitmap, 0.0f, 0.0f, null);
canvas.drawBitmap(foregroundImageBitmap, 0.0f, 0.0f, null);
第二个图像(前景图像)必须具有阿尔法方面或您无法通过它看到的。
The second image (foreground image) has to have Alpha aspects or you can't see through it.
这篇关于安卓:来自另一个资源的绘制位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!