I think I found the answer guys. My main problem for looking for help with my problem was that I didn't know what the "paint can tool" functionality was called! But it turns out there is something called the Flood Fill Algorithm that is exactly what I'm talking about implementing. http://en.wikipedia.org/wiki/Flood_fill[^]
max29297
Posts
-
Implementing a "Paint Can"-type tool -
Implementing a "Paint Can"-type toolI was aware that it was not the image size, but the number of pixels in the shape being filled that was the problem, and that the recursion overflow error was occurring in the
changeColor()
method... Your solution does not implement the bucket feature in MS Paint, because when you use the paint bucket in Paint it fills all adjacent pixels of a similar color with the color of your choice, what you have given me only fills a rectangle with a certain color :/ Thanks for the reply though! -
Implementing a "Paint Can"-type toolHey guys! So I've been trying to get this utility method to work for a while and can't seem to stop overloading the stack. The method should be able to emulate the Paint Can Tool in MS Paint. It takes a BufferedImage, the x- and y-coordinates of the point to apply the method to, and the color with which to paint the area. My implementation is a recursive one, and I know this is the reason for the overflow, but I haven't done any complex recursive method writing as of yet and don't know how I can fix my problem. Here is the code I've written:
static void paintCan(BufferedImage image, int x, int y, Color color) {
int[][] array = new int[image.getWidth()][image.getHeight()];for (int r = 0; r < image.getHeight(); r++) for (int c = 0; c < image.getWidth(); c++) array\[c\]\[r\] = image.getRGB(c, r); changeColor(array, x, y, array\[x\]\[y\], color.getRGB()); for (int r = 0; r < image.getHeight(); r++) for (int c = 0; c < image.getWidth(); c++) image.setRGB(c, r, array\[c\]\[r\]);
}
static void changeColor(int[][] image, int x, int y, int from, int to) {
if (image[x][y] == from) {
image[x][y] = to;int left = x - 1; int right = x + 1; int up = y - 1; int down= y + 1; if (left >= 0) changeColor(image, left, y, from, to); if (right < image.length) changeColor(image, right, y, from, to); if (up >= 0) changeColor(image, x, up, from, to); if (down < image\[0\].length) changeColor(image, x, down, from, to); }
}
This method works perfectly for smaller areas, but when the area selected at the (x, y) point requires too much recursion, a runtime error is thrown. Does anyone know how I can get the method to use less memory and not overload the stack? Help is very appreciated :) Thank you! -max
-
KeyListener - keyPressed delayWell thanks for all of your wonderful help guys, but I just thought I'd let you know that I went ahead and used my idea with the
boolean
s. -
Now this is what I call a funny christmas video!....That's pretty sick....
-
KeyListener - keyPressed delayHey guys! Just a quick question... So I've added a
KeyListener
to myJPanel
for a game I'm making, and everything is working out fine, except for one thing: When I hold down a key,keyPressed
is called once, followed by a delay, followed by several consecutive calls of thekeyPressed
method. I understand that this has to do with the way key events are processed and that you can adjust this delay within the control panel, but is there any way to remove this delay completely? I'm thinking what I'm going to end up doing is creating aboolean keyDown
variable which is set to true onkeyPressed
and to false onkeyReleased
. Any other ideas? :) -
The Noisy Screen SaverOnly happens with mine... Hmm...
-
The Noisy Screen SaverThanks to all, I'm sorry I wasn't as concise as I should have been... A few seconds after the screen saver pops up after the set time of 1 minute, there is a whirring sound from the back of my CPU. It is a desktop computer, and I'm not completly sure, Simon, what it is that's making the sound. If I had to guess, I'd guess the hard drive, but I'll check again once I get home. Your suggestion that I was loading an image on every frame of animation was one that I had thought of, unfortunately... I am loading several images, however these are loaded at the beginning. Would drawing these images on every frame have the same effect? I have double buffered the form and my timer has an interval of 2, I believe... This is rather fast but I want the animation to be smooth... The only reason the whirring is a problem for me is that I don want to turn the screen saver off every time I go to sleep haha.
-
The Noisy Screen SaverHi, I've made a screen saver in C#, and everything works out fine. The only thing that bothers me is the noise made by my computer while the screen saver is running. A few seconds after it comes on, the computer begins whirring and making a lot of noise... This problem is fixed when I increase the interval for my Timer object, but the animation becomes choppy. I would be perfectly happy with the screen saver if I could just get the darn computer to stop whirring... Any suggestions you guys? Thanks, Max
-
Running your programs on other machinesi know, it just came off to me that way when i first read it. thanks for the help!
-
Running your programs on other machinessorry, somehow the post sent before i added the link. i went back and added it. thanks for the logging tip, i'll try that. but man... i don't remember the people on these forms being so rude :(
I wish I could drive...
-
Running your programs on other machinesdoes it work on yours? and i've included in my question that i asked them to install the framework, and it gives the same message
I wish I could drive...
-
Running your programs on other machinesI've uploaded my program through box.net, and i've sent it to two people, and they both say that it says "an error occured, and the program needs to close". i've been giving it to them through this link: here. is it working for you guys? i've told them to download this too, but they're still saying it's not working... what could be going on?
-
Looking for the right enviornment to develop inlol nice
I wish I could drive...
-
Icon/Cursor Article...A while back I was looking for a program that could make cursors so that I could make one to use in a program I was making. I looked all over the internet, but couldn't find a free program that could do this (Well, some were free, but they either watermarked the icon or were only 30 day trials). So I came to the Code Project to see if they had any articles on icon making, and I just couldn't find one. And so I resorted to making a program myself. After about a week I had a good-looking cursor-making program (tell me if you want to see it). I didn't think it was that hard, and now I'm wondering... do you guys think I should write an article on the cursor (and icon, since they're almost identical) file format?
I wish I could drive...
-
StringsUsually when I'm joining a bunch of things to make a string, I'll just do like
string a = pt.X.ToString() + ", " + pt.Y.ToString();
. I was just wondering if this was considered bad code or something, because any example I see where they are joining things together like this, they use something else besides this. Should I be using something else to join things like this? (Wow that was a lot of "this")
I wish I could drive...
-
Microphone DataIs it possible to get sound data from the microphone? Everyone keeps telling me to go for SAPI, but I'm not doing speech recognition. I'm looking for a way to get data like the sound data in a .WAV file. I need to get the sound, like the Sound Recorder program that comes with Windows. Any suggestions?
Hippophobia - Fear of horses. What?
-
Playing Sounds through the SpeakersNot sure what arbitrary sounds are, but... Yes, it's going to be human speech mostly, but really, just any sound... I'm taking a look at SAPI right now. See, what I'm doing is taking the sound from the microphone, changing the pitch of the incoming sound, and then (immediately) playing the altered sound through the speakers. I was thinking I would start out by just playing the sound back normally through the speakers, without alterations, like a normal microphone hooked up to some speakers. Then, I'm going to need to know how to change the pitch of the sound and play simultaneously with the normal voice. I know that to play two sounds at once you pretty much just average the sine wavs, but I'm not sure how you would change the pitch. I was thinking that you would just increase the frequency of the wave and then increase the repetitions (so that it wouldn't come out faster), but I'm not quite sure how to do that yet... Also, I know how a .wav file works, so I could put the sound information into that, but I have no idea how I would play it through the speakers. Is there a way to change the position of that little thing inside the speaker (don't know what it's called, but it's the thing that moves back and forth to produce the sound) to the position that you specify?
I wish I could drive...
-
Playing Sounds through the SpeakersI'm making a program that requires you to take the sound from a microphone, change it (all it really has to do is change the pitch a little), and play it through the speakers. So... 1. How can you get the sound data from the microphone 2. How can you change the pitch (without speeding it up) 3. How can you play this changed sound data through the speakers? I haven't found any articles yet on CodeProject or Google. Any help here?
Hippophobia - Fear of horses. What?
-
MIDI Keyboard CommunicationI tried searching, but couldn't find anything... Guess I was typing the wrong words! Thanks for the help, anyway.
Hippophobia - Fear of horses. What?