Solved

Image Eraser algorithm?

Posted on 1997-10-22
5
481 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

749 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