• Post Reply Bookmark Topic Watch Topic
  • New Topic

paintcan  RSS feed

Ko Wey
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A question about 2D which I, the greenest greenhorn, simply cannot solve.
Everybody knows MS Paint (or Paintbrush)and its paintcan: when I hit a pixel(x,y) with the paintcan-tool, all its neighbouring pixels with the same color are painted with the color of the tool.
BufferedImage bi = ...//the image I am working with
Color paintCan = ... //the new color
int x, y //x and y coordinates from mouseListener, where I clicked
int nx, ny //coordinates from neighbouring pixel
int oldColor = bi.getRGB(x,y);
if (oldColor==bi.getRGB(nx,ny)){//if neighbour has same color
bi.setRGB(nx,ny,paintcan.getRGB()); //change its color
but how should i calculate the neighbouring pixels (nx, ny)? No matter the formula I cook, the result is always disappointing. Somebody an idea? Thanks for considering...
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!