RealisT Posted January 26, 2008 Share Posted January 26, 2008 Feels like a stupid question, but I can't find an answer among Documentation, Forum, or FAQ's. So here goes:How do I save an image from a Pic control to a File?I have an image sitting in a control created by GUICtrlCreatePic. I also have a FileSaveDialog all ready to go. But what is next? What command does the actual saving?There is no FileSave command. FileSaveDialog only prepares a filename; it does not do the actual saving, nor does it even list a 'save' type of command in the documentation among its "Related" list! _GDIPlus_ImageSaveToFile brings up nasty error messages (and crashes the script) when I use valid Pic control names and Filenames (besides, this isn't a _GDIPlus control). I really don't think I should have to resort to _ScreenCapture_Capture...in other words, there's gotta' be some other more elegant option out there.Any clarity on the subject would be appreciated. Link to comment Share on other sites More sharing options...
BrettF Posted January 26, 2008 Share Posted January 26, 2008 Maybe... #include <GUIConstants.au3> GUICreate("My GUI picture", 350, 300, -1, -1, $WS_SIZEBOX + $WS_SYSMENU); will create a dialog box that when displayed is centered GUISetBkColor(0xE0FFFF) $pic = GUICtrlCreatePic(@SystemDir & "\oobe\images\mslogo.jpg", 50, 50, 200, 50) $savemenu = GUICtrlCreateContextMenu($pic) $saveaction = GUICtrlCreateMenuItem("Save As...", $savemenu) GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $saveaction $File = GUICtrlRead ($pic) $EXT = StringSplit($File, ".") $save = FileSaveDialog("Save As...", "", "Picture Files (*." & $EXT[$EXT[0]] & ")") FileCopy ($File, $save) EndSelect WEnd Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
RealisT Posted January 26, 2008 Author Share Posted January 26, 2008 Maybe... #include <GUIConstants.au3> GUICreate("My GUI picture", 350, 300, -1, -1, $WS_SIZEBOX + $WS_SYSMENU); will create a dialog box that when displayed is centered GUISetBkColor(0xE0FFFF) $pic = GUICtrlCreatePic(@SystemDir & "\oobe\images\mslogo.jpg", 50, 50, 200, 50) $savemenu = GUICtrlCreateContextMenu($pic) $saveaction = GUICtrlCreateMenuItem("Save As...", $savemenu) GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $saveaction $File = GUICtrlRead ($pic) $EXT = StringSplit($File, ".") $save = FileSaveDialog("Save As...", "", "Picture Files (*." & $EXT[$EXT[0]] & ")") FileCopy ($File, $save) EndSelect WEnd Nothing happened when I tried this script. But your code opened my eyes. For some silly reason I had been thinking of the image in the pic control as some sort of volatile bitmap which wasn't a file, but of course that is not true. I will use FileCopy, as you did, to copy the source image to the destination image. Thanks! P.S. The GUICtrlRead doesn't seem to apply to Pic controls. It returns no value, so no value was parsed into $EXT. But you helped me out tremendously nonetheless. Thanks, mate! Link to comment Share on other sites More sharing options...
BrettF Posted January 26, 2008 Share Posted January 26, 2008 Nothing happened when I tried this script. But your code opened my eyes. For some silly reason I had been thinking of the image in the pic control as some sort of volatile bitmap which wasn't a file, but of course that is not true. I will use FileCopy, as you did, to copy the source image to the destination image. Thanks!P.S. The GUICtrlRead doesn't seem to apply to Pic controls. It returns no value, so no value was parsed into $EXT. But you helped me out tremendously nonetheless. Thanks, mate!Bah. I'm getting to forgetful lately. Acutally, I don't know of a way to get the current image loaded into a picture control. Can anyone shed some light to how? Glad it helped Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Squirrely1 Posted January 26, 2008 Share Posted January 26, 2008 (edited) @RealisT Whenever I am using GuiCtrlCreatePic, the image file I am using for it is considered ancillary to and necessary for my windowed application. You probably want to use the FileInstall function here. I would build the application under something like "C:\Program Files\My Program". Unless I use the FileInstall function to include and install the image file in an installer for my application (and so create a permanent copy of the image for use by my application's GUI window, installing it in that folder), I would use FileInstall to include and install the image temporarily under the folder @TempDir. Edited January 26, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
RealisT Posted January 28, 2008 Author Share Posted January 28, 2008 Bah. I'm getting to forgetful lately. Acutally, I don't know of a way to get the current image loaded into a picture control. Can anyone shed some light to how? Glad it helped Are you trying to do something other than GUICtrlSetImage() ? Link to comment Share on other sites More sharing options...
BrettF Posted January 28, 2008 Share Posted January 28, 2008 Are you trying to do something other than GUICtrlSetImage() ?Like the opposite. GUICtrlGetImage or something... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
RealisT Posted January 29, 2008 Author Share Posted January 29, 2008 Like the opposite. GUICtrlGetImage or something... The only thing I can think of would be to keep track of the name in a variable from the start. Or even an array $pic1[0] = GUICtrlCreatePic... $pic1[1] = "Splunge.jpg" Just a thought. One would think there would be a "Get" command for every "Set" command. Perhaps that's too symmetrical for this world... Link to comment Share on other sites More sharing options...
Squirrely1 Posted January 29, 2008 Share Posted January 29, 2008 (edited) The only thing I can think of...[inserts miscellaneous nonsense here] Be a Realist - this is the easiest way to get a picture to appear in your Graphical User Interface (GUI): ; How to include an image file so you can get it into your GUI - ; Hit the "Esc" key to exit ... HotKeySet("{ESC}", "Exit_Module") GUICreate("", 500, 500) ; C:\MyLovelyPicture.jpg in the next line, is the original of the image file: FileInstall("C:\MyLovelyPicture.jpg", @TempDir & "\UglyPic.jpg", 1) GUICtrlCreatePic(@TempDir & "\UglyPic.jpg", 10, 10) GUISetState() While 1 Sleep(90) WEnd Func Exit_Module() Exit EndFunc;==>Exit_Module Edited January 29, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
BrettF Posted January 29, 2008 Share Posted January 29, 2008 (edited) Be a Realist - this is the easiest way to get a picture to appear in your Graphical User Interface (GUI): ; How to include an image file so you can get it into your GUI - ; Hit the "Esc" key to exit ... HotKeySet("{ESC}", "Exit_Module") GUICreate("", 500, 500) ; C:\MyLovelyPicture.jpg in the next line, is the original of the image file: FileInstall("C:\MyLovelyPicture.jpg", @TempDir & "\UglyPic.jpg", 1) GUICtrlCreatePic(@TempDir & "\UglyPic.jpg", 10, 10) GUISetState() While 1 Sleep(90) WEnd Func Exit_Module() Exit EndFunc;==>Exit_ModuleHow does that answer the question? He asked how to get. Not set. I'd say he already knows that much. @OP, I would just do as you said. Store it in an array. Or a seperate varible. Whatever is easiest for you to either a) comprehend because arrays can be very daunting or for simplicity. The world used to be flat. See what they did to that myth? The worlds now round Edited January 29, 2008 by Bert Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Squirrely1 Posted January 29, 2008 Share Posted January 29, 2008 (edited) @Bert - it's not easy to figure out what he needed. I am thinking that what he is having a problem with is getting a picture to show up in his own GUI he built. For that to work in a compiled script that is self-sufficient, you have to use FileInstall somehow, unless the script knows of a picture already on the user's computer. What, more exhaustively now, do you suppose that he needs? Edited January 29, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
BrettF Posted January 29, 2008 Share Posted January 29, 2008 @Bert - it's not easy to figure out what he needed. I am thinking that what he is having a problem with is getting a picture to show up in his own GUI he built. For that to work in a compiled script that is self-sufficient, you have to use FileInstall somehow, unless the script knows of a picture already on the user's computer.What, more exhaustively now, do you suppose that he needs?OP said: How do I save an image from a Pic control to a File? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Squirrely1 Posted January 29, 2008 Share Posted January 29, 2008 (edited) OP said: How do I save an image from a Pic control to a File?So you think that he is trying en masse, to programmatically steal graphics from off someone else's GUI that they made?I steal girlie pix from the web, en masse, but not programmatically, pragmatically rather. Consider the case of my forum avatar - that's Hayley Mills' spacesuit as it appeared in the movie Tiger Bay (1959) - two years after I was born - I like older gals. Edited January 29, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
BrettF Posted January 29, 2008 Share Posted January 29, 2008 So you think that he is trying en masse, to programmatically steal graphics from off someone else's GUI that they made?I steal girlie pix from the web, en masse, but not programmatically, pragmatically rather. Consider the case of my forum avatar - that's Hayley Mills' spacesuit as it appeared in the movie Tiger Bay (1959) - two years after I was born - I like older gals.I don't know. It apears that he is trying to add saving it into his GUI, and we gave him an alterntive... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Squirrely1 Posted January 29, 2008 Share Posted January 29, 2008 (edited) I don't know. It apears that he is trying to add saving it into his GUI, and we gave him an alterntive...Well if he can't figure out where it is after he extracts it using FileInstall, and we tell him that that its filepath is the second parameter of the FileInstall function, I could end up obligated to refer him directly to Verse 1 of the Canon of Valik. Edited January 29, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
BrettF Posted January 30, 2008 Share Posted January 30, 2008 Well if he can't figure out where it is after he extracts it using FileInstall, and we tell him that that its filepath is the second parameter of the FileInstall function, I could end up obligated to refer him directly to Verse 1 of the Canon of Valik. What if the image is a radar downloaded of the internet? Hmmmmm?? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
RealisT Posted January 30, 2008 Author Share Posted January 30, 2008 What if the image is a radar downloaded of the internet? Hmmmmm??Crazy notions aside, my script is for saving a screen-captured image to a specified file. But since the capture is already a file, the FileCopy() advice works perfectly in getting the file to the user's desired path via the FileSaveDialog(). So everything's good.I'll leave the colorful "extra-curricular activities" to someone else.I believe that Bert's question about determining the image within a pic control also got (somewhat) addressed. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now