Witam
W jaki sposób można zmieszać kolory dwóch bitmap tak żeby:
- Końcowa bitmapa miała kanał alpha taki jak pierwsza
- Kolor (rbg) był równy połączeniu kolorów dwóch bitmap z według kanału alpha?
Poniższy kod realizuje 2 punkt:
private Bitmap Blend(Bitmap Src_01, Bitmap Src_02, int Alpha){
Bitmap Result = Bitmap.createBitmap(Src_01.getWidth(), Src_01.getHeight(), Bitmap.Config.ARGB_8888);
Canvas newCanvas = new Canvas(Result);
newCanvas.drawBitmap(Src_01, 0, 0, null);
Paint paint = new Paint();
paint.setAlpha(Alpha);
if (Src_01.getWidth() != Src_02.getWidth() || Src_01.getHeight() != Src_02.getHeight()){
Bitmap Src_03 = Bitmap.createScaledBitmap(Src_02, Src_01.getWidth(), Src_01.getHeight(), false);
newCanvas.drawBitmap(Src_03, 0, 0, paint);
}else {
newCanvas.drawBitmap(Src_02, 0, 0, paint);
}
return Result;
}
Poniższy kod powinien realizować oba punkty, jednak efekt jest zupełni inny niż oczekiwany:
private Bitmap BlendV2(Bitmap Src_01, Bitmap Src_02, int Alpha) {
Bitmap Result = Bitmap.createBitmap(Src_01.getWidth(), Src_01.getHeight(), Bitmap.Config.ARGB_8888);
Bitmap Src_03 = Bitmap.createBitmap(Src_02.getWidth(), Src_02.getHeight(), Bitmap.Config.ARGB_8888);
if (Src_01.getWidth() != Src_02.getWidth() || Src_01.getHeight() != Src_02.getHeight()) {
Src_03 = Bitmap.createScaledBitmap(Src_02, Src_01.getWidth(), Src_01.getHeight(), false);
}
Canvas canvas = new Canvas(Result);
canvas.drawBitmap(Src_01, 0, 0, null);
canvas.setBitmap(Src_03);
canvas.drawBitmap(Src_02, 0, 0, null);
for (int TB_01 = 0; TB_01 < Src_01.getWidth(); ++TB_01){
for (int TB_02 = 0; TB_02 < Src_01.getHeight(); ++TB_02) {
int Color_01 = Result.getPixel(TB_01, TB_02);
int ColorAlpha_01 = Color_01 / (256*256*256);
int ColorRGB_01 = Color_01 - ColorAlpha_01 * 256 * 256 * 256;
int Color_02 = Src_03.getPixel(TB_01, TB_02);
int ColorAlpha_02 = Color_02 / (256*256*256);
int ColorRGB_02 = Color_02 - ColorAlpha_02 * 256 * 256 * 256;
int ColorRGB_03 = (ColorRGB_01 + ColorRGB_02 * Alpha / 256) / 2;
int Color_03 = ColorAlpha_01 * 256*256*256 + ColorRGB_03;
Result.setPixel(TB_01, TB_02, Color_03);
}
}
return Result;
}
Dlaczego drugi kod nie działa tak jak powinien?
- Kod:
- Kod: