我正在处理图像合并应用程序我正在使用此代码。
Bitmap.Config config = bm1.getConfig();
if (config == null) {
config = Bitmap.Config.ARGB_8888;
}
newBitmap = Bitmap.createBitmap(w, h, config);
Canvas newCanvas = new Canvas(newBitmap);
newCanvas.drawBitmap(bm1, 0, 0, null);
Paint paint = new Paint();
paint.setAlpha(128);
newCanvas.drawBitmap(bm2, 0, 0, paint);
答案 0 :(得分:0)
您可以使用以下内容:
https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html
可在此处找到不同模式的详细信息和结果:
http://ssp.impulsetrain.com/porterduff.html
只需选择所需的算法并在位图上使用它。
答案 1 :(得分:0)
private Bitmap ProcessingBitmap() {
Bitmap bm1 = null;
Bitmap bm2 = null;
Bitmap newBitmap = null;
try {
bm1 = myBitmap;
bm2 = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.bc01), bm1.getWidth(), bm1.getHeight(), true);
int w;
if (bm1.getWidth() >= bm2.getWidth()) {
w = bm1.getWidth();
} else {
w = bm2.getWidth();
}
int h;
if (bm1.getHeight() >= bm2.getHeight()) {
h = bm1.getHeight();
} else {
h = bm2.getHeight();
}
Bitmap.Config config = bm1.getConfig();
if (config == null) {
config = Bitmap.Config.ARGB_8888;
}
newBitmap = Bitmap.createBitmap(w, h, config);
Canvas newCanvas = new Canvas(newBitmap);
//define half/half area
Rect rect1Half = new Rect(0, 0, ((bm1.getWidth() * 100) / 100),
bm1.getHeight());
Rect rect2Half = new Rect(((bm2.getWidth() * value) / 100) + 1,
0, bm2.getWidth(), bm2.getHeight());
newCanvas.drawBitmap(bm1, rect1Half, rect1Half, null);
Paint paint = new Paint();
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
// paint.setAlpha(valueAlpha);
paint.setMaskFilter(new BlurMaskFilter(50, BlurMaskFilter.Blur.NORMAL));
newCanvas.drawBitmap(bm2, rect2Half, rect2Half, paint);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
image.setImageBitmap(newBitmap);
return newBitmap;
}
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); paint.setMaskFilter(new BlurMaskFilter(50,BlurMaskFilter.Blur.NORMAL));
是半径为50的blur blurfilter的主要代码。