• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Applet graphics

Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic