我想删除特定的颜色,当我设置
wrres.setSample(x, y, 0, wrsrc.getSample(x, y, 0)) ;
我没有错误,但当我设置其他类似 wrres.setSample(x, y, 1, wrsrc.getSample(x, y, 1)) ;
那我有
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
at java.awt.image.MultiPixelPackedSampleModel.getSample(MultiPixelPackedSampleModel.java:359)
at java.awt.image.Raster.getSample(Raster.java:1648)
它给了我相同的图像(刚刚复制) BufferedImage imres = user_space(img,1);
```
int height = img.getHeight();
int width = img.getWidth();
BufferedImage imsrc = img; // The source image, RGBA
BufferedImage imres = user_space(img,1); // The resulting image, RGB or BGR
WritableRaster wrsrc = imsrc.getRaster() ;
WritableRaster wrres = imres.getRaster() ;
for (int y=0 ; y < img.getHeight() ; y++)
for (int x=0 ; x < img.getWidth() ; x++)
{
wrres.setSample(x, y, 0, wrsrc.getSample(x, y, 0)) ;
wrres.setSample(x, y, 1, wrsrc.getSample(x, y, 1)) ;
wrres.setSample(x, y, 2, wrsrc.getSample(x, y, 2)) ;
}
return
new BufferedImage(imsrc.getColorModel(),wrres,imsrc.getColorModel().isAlphaPremultiplied(), null);
}
如何使用setsample设置不同的颜色,而不仅仅是黑色和白色(波段等于0)
我不想使用BuffereImage中的getrgb
暂无答案!
目前还没有任何答案,快来回答吧!