我想在黑莓中的图像上应用棕褐色效果。 我已经尝试过,但没有得到100%的棕褐色效果。 这是我尝试过的棕褐色效果的代码。我使用了getARGB()
和setARGB()
位图类的方法。棕褐色在黑莓中的图像效果
public Bitmap changetoSepiaEffect(Bitmap bitmap) {
int sepiaIntensity=30;//value lies between 0-255. 30 works well
// Play around with this. 20 works well and was recommended
// by another developer. 0 produces black/white image
int sepiaDepth = 20;
int w = bitmap.getWidth();
int h = bitmap.getHeight();
// WritableRaster raster = img.getRaster();
// We need 3 integers (for R,G,B color values) per pixel.
int[] pixels = new int[w*h*3];
// raster.getPixels(0, 0, w, h, pixels);
bitmap.getARGB(pixels, 0, w, x, y, w, h);
// Process 3 ints at a time for each pixel.
// Each pixel has 3 RGB colors in array
for (int i=0;i<pixels.length; i+=3) {
int r = pixels[i];
int g = pixels[i+1];
int b = pixels[i+2];
int gry = (r + g + b)/3;
r = g = b = gry;
r = r + (sepiaDepth * 2);
g = g + sepiaDepth;
if (r>255) r=255;
if (g>255) g=255;
if (b>255) b=255;
// Darken blue color to increase sepia effect
b-= sepiaIntensity;
// normalize if out of bounds
if (b<0) {
b=0;
}
if (b>255) {
b=255;
}
pixels[i] = r;
pixels[i+1]= g;
pixels[i+2] = b;
}
//raster.setPixels(0, 0, w, h, pixels);
bitmap.setARGB(pixels, 0, w, 0, 0, w, h);
return bitmap;
}
你是什么意思,它并没有得到100%的棕褐色效果?它做什么,你不想要? – 2012-03-30 06:39:20
棕褐色效果意味着棕色+灰色的颜色....我没有得到任何棕色的颜色 – 2012-03-30 07:07:33
我已经使用过你的代码,但是我的图像保持原样。没有发生变化..但是当我返回原图像,而不是新的image.It显示一些效果。你在黑莓模拟器上测试你的发布代码。 – 2012-03-30 11:03:56