Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet graphics

 
Bob Moranski
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I was wondering if anyone knows how to create a partially erased effect that would partially reveal the images/color underneath?
Thanks.
 
Sean MacLean
author
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a suggestion that may give you a direction to start off in. Firstly, have a look at some tutorials on ImageFilters. They are a really handy way of manipulating Images. I'll outline the steps that I think will get you going:
1) Define the area that you want to be erased and create and Image object out of it.
2) Create a custom "EraseFilter" by extending java.awt.image.RGBImageFilter.
3) Design the filter so that, upon instantiation, it holds the foreground color and the backgraound image in arrays. Make the foreground the solid color you want to erase.
4) Define a mousehandler that is aware of the bounds of the Image you want to erase over.
5) Have the mouseEvent set it's coordinates in the filter as it erases and after some predetermines distance (1 pixel, 10 pixels, whatever is smooth) call filterRGB.
6) Within the filterRGB() method (in the ImageFilter), swap the foreground pixels to the background pixels of the image ( that you have stored in arrays in the ImageFilter, remember?)
7) call repaint (or have the filterRGB in the repaint()) and simple call g.drawImage( ..... ) on the original image. Magically the newly erased bits will appear.
This is similar to an ImageFade thing that I did in that I started with two Images - one on top of the other - and then looped using the filterRGB() to mathematically fade the pixel values from one image to the other. Worked like a charm and was really smooth. Good luck and have fun!
Sean
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic