[RESOLVED] SavePicture event using 50% CPU. Any way to reduce that?
Hello,
I am using the following code in a command button.
VB Code:
SavePicture frmMain.Picture2.Image, "C:\Data\" & Format(Now, "hhmmss") & ".bmp"
Now when I click the button I watch my CPU and as it is saving the picture to the file it uses about 50% of my CPU. This is saving a picturebox that is about the same size as the screen. When the pic is small it doesn't take much CPU. only when it is a big pic. Is there any way to reduce the quality or somthing to make it not use so much CPU?
Thank you and have a great evening.
Stilekid007
Re: SavePicture event using 50% CPU. Any way to reduce that?
Conversation with mind and subconscious.
Mind: Arrrgg no one replied!
Mind: Maybe it was too late at night when I posted?
Subconscious: Yea maybe so but oh well get over it, someone may still respond.
Mind: Hmm maybe but I think I will post a new post in the thread to bump me to the top of the list so someone will see my post..
Subconscious: NO, don't you dare! Thats cheating!
Mind: So what no one will respond if I don't!
Subconscious: Isn't it better to suffer then cheat?
Subconscious: Don't push that button!
Subconscious: I'm warning you! Don't push that button!
Subconscious: NO WAIT! NO NO NO NO!!!! AHHHHHHHHHHHHHH!!!!!!
Stilekid007: Wow that was stupid.
Re: SavePicture event using 50% CPU. Any way to reduce that?
Argh... Try making your own function for saving pictures :sick:
Once I tried making one... it's not actually that hard... search the web for a save-to-bmp function... then maybe you can control it better, perhaps adding a doevents in the midst of it.
Re: SavePicture event using 50% CPU. Any way to reduce that?
Hmm, Ok, I will see what I can do. I already had a doevents in the code riht above the savepicture function.
But thanks for your reply!
Stilekid007
Re: SavePicture event using 50% CPU. Any way to reduce that?
What is wrong with the 50% cpu usage?
Is it causing other apps to not run at all?
Re: SavePicture event using 50% CPU. Any way to reduce that?
Yea it makes the computer slow for about 2 seconds everytime it saves an image making everything else skip.
Re: SavePicture event using 50% CPU. Any way to reduce that?
50% CPU is not a bad thing - seems that it is that during that 2 seconds, it is such an intensive operation, that you would prefer it to run slower and yield easier to other apps...
Sounds like the only thing you could do is write you own routine to save the picture and perform a DOEVENTS every so often in the loop.
Re: SavePicture event using 50% CPU. Any way to reduce that?
Saving a large file like that with the 1-2 second pause is normal. It's the same in the DirectX made applications when you press a key to take a snapshot of the entire window it's in.
Re: SavePicture event using 50% CPU. Any way to reduce that?
Quote:
Originally Posted by stilekid007
... I already had a doevents in the code riht above the savepicture function. ...
That's what causing your CPU to go crazy for a little while, though ... ;)
Re: SavePicture event using 50% CPU. Any way to reduce that?
Ok, so its not anything I really need to worry about it? I don't think it would hurt much anyway. The program runs 24/7 so I was hoping there would be a way to lower that CPU usage but the savepicture event won't be very often. So I think I am good. I was just wondering if there was anything out there that was easy and known...
So thank you all for your replys.
You all are great!
Stilekid007
Re: SavePicture event using 50% CPU. Any way to reduce that?
Quote:
Originally Posted by RhinoBull
That's what causing your CPU to go crazy for a little while, though ... ;)
Yea I see if I take the DOevents out it lowers it a tad - but just a tad. ;)
:P
Thanks man!
Stilekid007
Re: SavePicture event using 50% CPU. Any way to reduce that?
DoEvents is considered the worse VB function ever written. There are many discussions in VBForums on it. :)
I even have a thread in the code bank that gives you alternatives:bigyello:
http://www.vbforums.com/showthread.php?t=315416
Re: SavePicture event using 50% CPU. Any way to reduce that?
Quote:
Originally Posted by Jacob Roman
Well, that is a very good thread. For someone like me who knows nothing about DoEvents. ;)
Thank you sir!
Stilekid007
Re: SavePicture event using 50% CPU. Any way to reduce that?
Quote:
Originally Posted by stilekid007
Yea I see if I take the DOevents out it lowers it a tad - but just a tad. ;)
:P
Thanks man!
Stilekid007
That's just a high level of it (DoEvents) ...
Re: SavePicture event using 50% CPU. Any way to reduce that?
Quote:
Originally Posted by Jacob Roman
DoEvents is considered the worse VB function ever written. ...
I will agree on this one more time ... ;)
Re: SavePicture event using 50% CPU. Any way to reduce that?
Ok, well that concludes this thread ;) hehe :P
Thank you all!
Stilekid007