如何concate /合并两个位图,使他们在android的一个图像 [英] How to concate/combine two bitmaps and make them one image in android
本文介绍了如何concate /合并两个位图,使他们在android的一个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能告诉我如何在Android的合并或连接两个位图图像为一体?
Can anyone tell me how to combine or concatenate two bitmap images into one in android?
推荐答案
您可以用画图尝试。 在这里,一个简单的例子:
You can try with Paint. Here a short example:
package com.cyrilmottier.android.masking;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuffXfermode;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new IconView(this));
}
private class IconView extends View {
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Bitmap mIcon;
private Bitmap mIconGlossy;
private Bitmap mIconMask;
public IconView(Context context) {
super(context);
// Prepares the paint that will be used to draw our icon mask. Using
// PorterDuff.Mode.DST_IN means the image that will be drawn will
// mask the already drawn image.
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
// Let's retrieve all icon pieces as Bitmaps.
final Resources res = context.getResources();
mIcon = BitmapFactory.decodeResource(res, R.drawable.icon_metromap_fake);
mIconGlossy = BitmapFactory.decodeResource(res, R.drawable.icon_glossy);
mIconMask = BitmapFactory.decodeResource(res, R.drawable.icon_mask);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.save();
// Translate the canvas in order to draw the icon in the center of
// the view
canvas.translate((getWidth() - mIcon.getWidth()) >> 1, (getHeight() - mIcon.getHeight()) >> 1);
// We're now ready to drawn our iPhone-like icon :)
canvas.drawBitmap(mIcon, 0, 0, null);
canvas.drawBitmap(mIconGlossy, 0, 0, null);
canvas.drawBitmap(mIconMask, 0, 0, mPaint);
canvas.restore();
}
}
}
这篇关于如何concate /合并两个位图,使他们在android的一个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文