2
public class BlendablePicture extends Picture {
    public BlendablePicture(String filename) {
        super(filename);
    }

    public void blendRectWithWhite(int xMin, int yMin, int xMax, int yMax,
            double a) {
        int x;
        x = xMin;
        while (x <= xMax) {
            int y;
            y = yMin;
            while (y <= yMax) {
                Pixel refPix = this.getPixel(x, y);
                refPix.setRed((int) Math.round(refPix.getRed() * (1.0 + a)));
                refPix.setGreen((int) Math.round(refPix.getGreen() * (1.0 + a)));
                refPix.setBlue((int) Math.round(refPix.getBlue() * (1.0 + a)));

                y = y + 1;
            }
        }
    }
}

白をピクセルとブレンドする必要がありますが、代わりにこのコードはすべてを明るくしています! 次のようにする必要があります。

ブレンドホワイト - イラスト付き

このコードに関するヘルプをいただければ幸いです。

4

1 に答える 1

3

それ以外の

refPix.setRed ( (int) Math.round (refPix.getRed () * (1.0+ a) ));

次のようなものを試してください

refPix.setRed ( (int) Math.round (refPix.getRed()*(1.0-a)+255*a ));

a = 1.0の場合、R * 0.0 + 255 * 1.0=255になります

a = 0.0の場合、R * 1.0 + 255 * 0.0=Rになります

a = 0.5の場合、R * 0.5 + 255 * 0.5(半分)を取得します

これは、白だけでなく任意の色で機能します。赤、緑、青の255を、ブレンドする色の色に置き換えるだけで、RGB平均のブレンドが得られます。

于 2013-03-12T22:25:06.960 に答える