Blackberry 黑莓中的乌贼图像效应
我正在尝试在黑莓手机的图像上应用乌贼色效果。 我试过了,但没有100%的乌贼墨效果。 这是代码,我已经尝试了乌贼效应。 我使用了位图类的Blackberry 黑莓中的乌贼图像效应,blackberry,Blackberry,我正在尝试在黑莓手机的图像上应用乌贼色效果。 我试过了,但没有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
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;
}
公共位图更改为位图效果(位图){
int sepiaIntensity=30;//值介于0-255之间。30效果良好
//试试这个。20很好用,是推荐的
//由另一个开发人员创建。0生成黑白图像
int-sepiaDepth=20;
int w=bitmap.getWidth();
int h=bitmap.getHeight();
//WritableRaster raster=img.getRaster();
//我们需要每像素3个整数(用于R、G、B颜色值)。
int[]像素=新的int[w*h*3];
//获取像素(0,0,w,h,像素);
getARGB(像素,0,w,x,y,w,h);
//为每个像素一次处理3个整数。
//阵列中每个像素有3种RGB颜色
对于(inti=0;i255)r=255;
如果(g>255)g=255;
如果(b>255)b=255;
//加深蓝色以增加乌贼墨效果
b-=乌贼墨强度;
//如果超出范围,则进行规范化
如果(b255){
b=255;
}
像素[i]=r;
像素[i+1]=g;
像素[i+2]=b;
}
//光栅设置像素(0,0,w,h,像素);
setARGB(像素,0,w,0,0,w,h);
返回位图;
}
此呼叫:
bitmap.getARGB(pixels, 0, w, x, y, w, h);
返回一个int[]数组,其中每个int表示0xAARRGGBB格式的颜色。这与之前使用JavaSE的Raster类编写的代码不同
编辑:BlackBerry的固定方法:
public static 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();
// Unlike JavaSE's Raster, we need an int per pixel
int[] pixels = new int[w * h];
// We get the whole image
bitmap.getARGB(pixels, 0, w, 0, 0, w, h);
// Process each pixel component. A pixel comes in the format 0xAARRGGBB.
for (int i = 0; i < pixels.length; i++) {
int r = (pixels[i] >> 16) & 0xFF;
int g = (pixels[i] >> 8) & 0xFF;
int b = pixels[i] & 0xFF;
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;
}
// Now we compose a new pixel with the modified channels,
// and an alpha value of 0xFF (full opaque)
pixels[i] = ((r << 16) & 0xFF0000) | ((g << 8) & 0x00FF00) | (b & 0xFF) | 0xFF000000;
}
// We return a new Bitmap. Trying to modify the one passed as parameter
// could throw an exception, since in BlackBerry not all Bitmaps are modifiable.
Bitmap ret = new Bitmap(w, h);
ret.setARGB(pixels, 0, w, 0, 0, w, h);
return ret;
}
public静态位图changetoSepiaEffect(位图){
int sepiaIntensity=30;//值介于0-255之间。30效果良好
//试试这个。20很好用,是推荐的
//由另一个开发人员创建。0生成黑白图像
int-sepiaDepth=20;
int w=bitmap.getWidth();
int h=bitmap.getHeight();
//与JavaSE的光栅不同,我们需要每像素整数
int[]像素=新的int[w*h];
//我们得到了整个图像
getARGB(像素,0,w,0,0,w,h);
//处理每个像素组件。像素的格式为0xAARGGBB。
对于(int i=0;i>16)&0xFF;
int g=(像素[i]>>8)&0xFF;
int b=像素[i]&0xFF;
int gry=(r+g+b)/3;
r=g=b=gry;
r=r+(九月*2);
g=g+sepiaDepth;
如果(r>255)
r=255;
如果(g>255)
g=255;
如果(b>255)
b=255;
//加深蓝色以增加乌贼墨效果
b-=乌贼墨强度;
//如果超出范围,则进行规范化
if(b<0){
b=0;
}
如果(b>255){
b=255;
}
//现在我们用修改后的通道合成一个新像素,
//α值为0xFF(完全不透明)
像素[i]=((r此调用:
bitmap.getARGB(pixels, 0, w, x, y, w, h);
返回一个int[]数组,其中每个int表示格式为0xAARRGGBB的颜色。这与以前使用JavaSE光栅类的代码不同
编辑:BlackBerry的固定方法:
public static 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();
// Unlike JavaSE's Raster, we need an int per pixel
int[] pixels = new int[w * h];
// We get the whole image
bitmap.getARGB(pixels, 0, w, 0, 0, w, h);
// Process each pixel component. A pixel comes in the format 0xAARRGGBB.
for (int i = 0; i < pixels.length; i++) {
int r = (pixels[i] >> 16) & 0xFF;
int g = (pixels[i] >> 8) & 0xFF;
int b = pixels[i] & 0xFF;
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;
}
// Now we compose a new pixel with the modified channels,
// and an alpha value of 0xFF (full opaque)
pixels[i] = ((r << 16) & 0xFF0000) | ((g << 8) & 0x00FF00) | (b & 0xFF) | 0xFF000000;
}
// We return a new Bitmap. Trying to modify the one passed as parameter
// could throw an exception, since in BlackBerry not all Bitmaps are modifiable.
Bitmap ret = new Bitmap(w, h);
ret.setARGB(pixels, 0, w, 0, 0, w, h);
return ret;
}
public静态位图changetoSepiaEffect(位图){
int sepiaIntensity=30;//值介于0-255之间。30效果良好
//试试这个。20很好用,是推荐的
//由另一个开发人员创建。0生成黑白图像
int-sepiaDepth=20;
int w=bitmap.getWidth();
int h=bitmap.getHeight();
//与JavaSE的光栅不同,我们需要每像素整数
int[]像素=新的int[w*h];
//我们得到了整个图像
getARGB(像素,0,w,0,0,w,h);
//处理每个像素组件。像素的格式为0xAARGGBB。
对于(int i=0;i>16)&0xFF;
int g=(像素[i]>>8)&0xFF;
int b=像素[i]&0xFF;
int gry=(r+g+b)/3;
r=g=b=gry;
r=r+(九月*2);
g=g+sepiaDepth;
如果(r>255)
r=255;
如果(g>255)
g=255;
如果(b>255)
b=255;
//加深蓝色以增加乌贼墨效果
b-=乌贼墨强度;
//如果超出范围,则进行规范化
if(b<0){
b=0;
}
如果(b>255){
b=255;
}
//现在我们用修改后的通道合成一个新像素,
//α值为0xFF(完全不透明)
像素[i]=((r)你说它没有100%的乌贼墨效果是什么意思?它做了什么你不想做的事?乌贼墨效果的意思是-棕色+灰色…我没有得到任何棕色我使用了你的代码,但我的图像保持原样..没有变化..但是当我返回原始图像而不是新图像时,它显示了一些效果..你测试了你的在blackberry simulator上发布代码。你说它没有100%的深褐色效果是什么意思?它做了什么你不想做的事?深褐色效果的意思是-棕色+灰色…我没有得到任何棕色颜色我使用了你的代码,但我的图像保持原样..没有变化..但是当我返回原始图像而不是新图像时,它显示了一些效果..你是否在blackberry simulator上测试了你发布的代码。你的sepia代码内部循环应该可以工作。检查getARGB
方法调用中的x和y是否为0。此外,循环中的增量应该从i+=3
更改为i++
。代码中仍然存在一些缺陷,因为试图修改位图而不是r重新启动一个新的,或者由于我的系统中的错误,像素是完全透明的