How I can set pixel in the Shape with the specific RGB?
For example, I have a polygon and I need to fill it with the specific RGB. How can I do it? I tried to convert shape to image, but then I can't set a pixel with setRGB method from BufferedImage(pixel color wasn't changing!):
...
Rectangle2D r = pgnProjection.getBounds();
BufferedImage rectBuffIm = new BufferedImage(r.getBounds().width, r.getBounds().height,
BufferedImage.TYPE_BYTE_BINARY);
for(int i = rectBuffIm.getWidth()/2, j = rectBuffIm.getHeight()/2; rectBuffIm.getWidth()>i && rectBuffIm.getHeight()>j; j++, i++)
rectBuffIm.setRGB(i, j, rgb);
Graphics2D gr2D = rectBuffIm.createGraphics();
gr2D.translate(-pgnProjection.getBounds().x, -pgnProjection.getBounds()开发者_如何学C.y);
gr2D.draw(pgnProjection);
gr2D.dispose();
...
Also, image background was black, and set pixels were always white.
Call Graphics.setClip(Shape)
followed by the drawing operations. See here for an example.
Graphics.fillPolygon()
精彩评论