Jump to content

Save Image


RealisT
 Share

Recommended Posts

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

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
Link to comment
Share on other sites

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

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 :D
Link to comment
Share on other sites

@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 by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

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

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 by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

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
How 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 :D for simplicity. The world used to be flat. See what they did to that myth? The worlds now round :P

Edited by Bert
Link to comment
Share on other sites

@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 by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

@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?

Link to comment
Share on other sites

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 by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

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...
Link to comment
Share on other sites

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. :D Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

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. :D

What if the image is a radar downloaded of the internet? Hmmmmm??
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...