我要删除特定的颜色,并且在设置时
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),还设置不同的颜色'
我不想使用BufferedImage中的getRGB