Solved

Image Eraser algorithm?

Posted on 1997-10-22
5
477 Views
Last Modified: 2008-03-10
Hi. I am trying to learn Java. I am attempting to write an image processing application. I want to be able to dynamically erase selected areas of a .gif or .jpg image with the drag of the mouse. So far, I have been able to make the entire image transparent in one fell swoop using an image consumer (Java's PixelGrabber class )to place all the image's pixels into an array and then recreating and filtering each pixel with an image producer (MemoryImageSource class).

I have tried placing the relevant "make transparent" code inside the mousedrag event handler method with no luck. What am I overlooking? Please does anyone know of an algorithm that does this sort of thing? I'm not asking for 'working code' - that would take the fun out of it for me. Just a relatively self-explanatory algorithm would be most appreciated.

TIA
0
Comment
Question by:wboyd
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:gnawed
ID: 1229394
Hmm, might be easier and faster to draw the image to an offscreen buffer, then draw over the offscreen image with a "brush" that is the same color as the background during the mouseDrag() and then blip the offscreen image onto the screen.
0
 
LVL 2

Author Comment

by:wboyd
ID: 1229395
Thanks gnawed for your answer. However, I'm afraid I can't accept it. I should have mentioned that I've done it that way in other excercises and you are correct - it is easier. I suppose it's more a matter of my curiosity about how to get the same sort of effect but using PixelGrabber and MemoryImageSource. In fact I've had some hopeful results in the past doing what you're suggesting drawing the transparent MemoryImageSource to an off-screen graphics context, etc. I should also add that there will be another .gif/.jpg image as the background onto which the erased image (foreground)  will be overlaid. So, I wanna erase the top image and leave (or at least appear to leave) the background image intact.
0
 
LVL 4

Accepted Solution

by:
rembo earned 200 total points
ID: 1229396

You can still do this without doing MemoryImageSource and
PixelGrabber.  PixelGrabber is painfully slow and it will
never run smoothly.  I have something that does exactly
what you're trying to do, and I'd be happy to mail you
the source using offscreen buffers and Images, but
not the PixelGrabber.  If that's acceptable, just give
me your e-mail and I'll send it to you.

-Tony

0
 
LVL 2

Author Comment

by:wboyd
ID: 1229397
Thanks Tony, for your answer. As I mentioned in my earlier comment to gnawed, I have already written some code that does what I want using offscreeen buffers and images as you are suggesting. I was curious to figure out how to do it using PixelGrabber and MemoryImageSource. Nevertheless, although I did orignally say I wasn't requesting working code, your offer might at least be helpful to compare the logic you used with what I've used.  Even though you say PixelGrabber is slow, etc. as long as you're sending the other stuff can you also please send an explanation of how you understand it would be done with PixelGrabber anyway? I need to learn the hard way :-) My email address is wboyd@clara.net Or, if that doesn't work zp374@city.ac.uk is my address at school. Thanks.
0
 
LVL 4

Expert Comment

by:rembo
ID: 1229398

I apologize for the delay as I was out of town and couldn't
access my system.  I have e-mailed you the files.  If you
have any trouble with them at all, please let me know, and
I'll put them up on my site for you to access them.

Hope that helps,

-Tony

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now