我正在尝试将图像左半部分用橙色着色,右半部分用栗色着色。我编写了我的代码,但每当我尝试时,它只返回纯橙色和栗色。所以这就是我想要做的。
我想用适量的橙色和栗色给左右着色,这样会像
像这样,我的不像这个例子那样工作。这是我的代码。
public Bitmap toHokie(Bitmap bmpOriginal) {
int width, height;
Bitmap bmOut = Bitmap.createBitmap(bmpOriginal.getWidth(),
bmpOriginal.getHeight(), bmpOriginal.getConfig());
height = bmOut.getHeight();
width = bmOut.getWidth();
int orangeFilter = new Color().rgb(255, 165, 0);
int maroonFilter = new Color().rgb(139, 0, 0);
for (int j = 0; j < height - 1; j++) {
for (int i = 0; i < width / 2 - 1; i++) {
int newColor = (int) ((double) (bmOut.getPixel(i, j) * 0.3) + ((double) (orangeFilter * 0.7)));
bmOut.setPixel(i, j, newColor);
}
}
for (int j = 0; j < height - 1; j++) {
for (int i = width / 2; i < width - 1; i++) {
double newColor = (bmOut.getPixel(i, j) * 0.3 + maroonFilter * 0.7);
bmOut.setPixel(i, j, (int) newColor);
}
}
return bmOut;
}
实际上,对于我的第二次尝试,它现在比以前更好,但它仍然是有线的......就像这样
我是这样固定的。
public Bitmap toHokie(Bitmap bmpOriginal) {
int width, height;
Bitmap bmOut = Bitmap.createBitmap(bmpOriginal.getWidth(),
bmpOriginal.getHeight(), bmpOriginal.getConfig());
height = bmOut.getHeight();
width = bmOut.getWidth();
int orangeFilter = new Color().rgb(255, 165, 0);
int maroonFilter = new Color().rgb(139, 0, 0);
for (int j = 0; j < height - 1; j++) {
for (int i = 0; i < width / 2 - 1; i++) {
int newColor = (int) ((bmpOriginal.getPixel(i, j) * 0.7) + ((orangeFilter * 0.3)));
bmOut.setPixel(i, j, newColor);
}
}
for (int j = 0; j < height - 1; j++) {
for (int i = width / 2; i < width - 1; i++) {
double newColor = (bmpOriginal.getPixel(i, j) * 0.3 + maroonFilter * 0.7);
bmOut.setPixel(i, j, (int) newColor);
}
}
return bmOut;
}