Solved

Image Eraser algorithm?

Posted on 1997-10-22
5
476 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.

708 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

12 Experts available now in Live!

Get 1:1 Help Now