Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

paintcan

 
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...
 
Acetylsalicylic acid is aspirin. This could be handy too:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!