Jump to content

Can i view images in my design ??


Go to solution Solved by mpower,

Recommended Posts

yea my question is can i view pics in my design and here is my source it is very simple :

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1_1 = GUICreate("Form1", 660, 444, 192, 145)
$file = GUICtrlCreateMenu("&File")
$open = GUICtrlCreateMenuItem("open"&@TAB&"", $file)
$save = GUICtrlCreateMenuItem("save", $file)
$Pic1 = GUICtrlCreatePic("", 16, 56, 561, 329)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $open
            ;here ,, is it right to allow me view images as i like or ?? 
            $o = FileOpenDialog("File Open", @DesktopDir , " TXT (*.jpg) " )
            GUICtrlSetImage( $Pic1 , FileRead( $o ) )

    EndSwitch
WEnd
Link to comment
Share on other sites

  • Solution

Try:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1_1 = GUICreate("Form1", 660, 444, 192, 145)
$file = GUICtrlCreateMenu("&File")
$open = GUICtrlCreateMenuItem("open"&@TAB&"", $file)
$save = GUICtrlCreateMenuItem("save", $file)
$Pic1 = GUICtrlCreatePic("", 16, 56, 561, 329)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $open
            ;here ,, is it right to allow me view images as i like or ?? 
            $o = FileOpenDialog("File Open", @DesktopDir , " TXT (*.jpg) " )
            GUICtrlSetImage( $Pic1 , $o)

    EndSwitch
WEnd
Link to comment
Share on other sites

 

Try:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1_1 = GUICreate("Form1", 660, 444, 192, 145)
$file = GUICtrlCreateMenu("&File")
$open = GUICtrlCreateMenuItem("open"&@TAB&"", $file)
$save = GUICtrlCreateMenuItem("save", $file)
$Pic1 = GUICtrlCreatePic("", 16, 56, 561, 329)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $open
            ;here ,, is it right to allow me view images as i like or ?? 
            $o = FileOpenDialog("File Open", @DesktopDir , " TXT (*.jpg) " )
            GUICtrlSetImage( $Pic1 , $o)

    EndSwitch
WEnd

i want to know why it didnt run with fileread ??

Edited by yousefsamy
Link to comment
Share on other sites

FileRead reads the contents of the file, FileOpenDialog returns the filename and GUICtrlSetImage requires a file name, not the contents of the file.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

FileRead reads the contents of the file, FileOpenDialog returns the filename and GUICtrlSetImage requires a file name, not the contents of the file.

but can you tell me how to make the window auto size with the size of the image ?? 

Link to comment
Share on other sites

You need to find out the size of the image and then make the GUI the same size, or stretch the image if it's too small to fit.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

This will resize the GUI and the Pic control to fit the image dimensions (with optional scaling):

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

_GDIPlus_Startup()

$iWidth = 500
$iHeight = 500

$iScale = 1 ;set scaling from 0.1 to x (e.g. 2 = scale image to 200% original size)

$hGUI = GUICreate("Form1", $iWidth, $iHeight, @DesktopWidth/2 - $iWidth/2, @DesktopHeight/2 - $iHeight/2)
$file = GUICtrlCreateMenu("&File")
$open = GUICtrlCreateMenuItem("open"&@TAB&"", $file)
$save = GUICtrlCreateMenuItem("save", $file)
$hPic = GUICtrlCreatePic("", 0, 0, 0, 0)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_Shutdown()
            Exit
        Case $open
            ;here ,, is it right to allow me view images as i like or ??
            $o = FileOpenDialog("File Open", @DesktopDir , " TXT (*.jpg) " )
            ConsoleWrite($o&@CRLF)
            $hImage = _GDIPlus_ImageLoadFromFile($o)
            $iX = _GDIPlus_ImageGetWidth($hImage)
            $iY = _GDIPlus_ImageGetHeight($hImage)
            _GDIPlus_ImageDispose($hImage)
            WinMove($hGUI, '', Default, Default, $iX * $iScale, $iY * $iScale + 45)
            GUICtrlSetPos($hPic, 0, 0, $iX * $iScale, $iY * $iScale)
            GUICtrlSetImage($hPic, $o)
    EndSwitch
WEnd
Link to comment
Share on other sites

 

This will resize the GUI and the Pic control to fit the image dimensions (with optional scaling):

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

_GDIPlus_Startup()

$iWidth = 500
$iHeight = 500

$iScale = 1 ;set scaling from 0.1 to x (e.g. 2 = scale image to 200% original size)

$hGUI = GUICreate("Form1", $iWidth, $iHeight, @DesktopWidth/2 - $iWidth/2, @DesktopHeight/2 - $iHeight/2)
$file = GUICtrlCreateMenu("&File")
$open = GUICtrlCreateMenuItem("open"&@TAB&"", $file)
$save = GUICtrlCreateMenuItem("save", $file)
$hPic = GUICtrlCreatePic("", 0, 0, 0, 0)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_Shutdown()
            Exit
        Case $open
            ;here ,, is it right to allow me view images as i like or ??
            $o = FileOpenDialog("File Open", @DesktopDir , " TXT (*.jpg) " )
            ConsoleWrite($o&@CRLF)
            $hImage = _GDIPlus_ImageLoadFromFile($o)
            $iX = _GDIPlus_ImageGetWidth($hImage)
            $iY = _GDIPlus_ImageGetHeight($hImage)
            _GDIPlus_ImageDispose($hImage)
            WinMove($hGUI, '', Default, Default, $iX * $iScale, $iY * $iScale + 45)
            GUICtrlSetPos($hPic, 0, 0, $iX * $iScale, $iY * $iScale)
            GUICtrlSetImage($hPic, $o)
    EndSwitch
WEnd

 

Yea bro this is what i want ^_^  but what about [[ guiplus ]]?? what the benefit from it ?

please explain to me your codes i want to under stand  consolewrite , winmove ,,, and etc ... 

Edited by yousefsamy
Link to comment
Share on other sites

ConsoleWrite($o&@CRLF)

This was here only for debugging purposes -  I was using this to see what value the variable $o was returning. To see it in action just run the script and watch the console in the bottom section of SciTE (assuming you are using SciTE to code).

You will notice that when you open an image the value of $o is the full directory path including the file name (e.g. C:WindowsExample.jpg).Alternatively you could display a MsgBox that shows the same thing: e.g. MsgBox(0,'',$o) would show a MsgBox with the text C:WindowsExample.jpg. ConsoleWrite is just a bit less intrusive, but both are good for debugging :)

It's definitely good to utilise ConsoleWrite whilst writing code to make sure you are working with the right values! 

GDI Plus is a library that works with images/graphics - someone has worked hard to write all the code for us to use to make it simpler. For example you could spend hours working our how to get the image dimensions but someone has already done this and has written a function called _GDIPlus_ImageGetWidth()

I don't really know much more about GDI Plus to be honest, I usually use these forums to find examples and also look at Help files (very important!!) You can actually click on every one of those functions right here in the forum and it would take you to a page explaining what each one does. That's the best place to start to understand how each function works.

WinMove allows us to change the size of the GUI (and even move the GUI around if we need to), but in our case we just resize the GUI to fit the image.

Hope this helps :)

Link to comment
Share on other sites

ConsoleWrite($o&@CRLF)

This was here only for debugging purposes -  I was using this to see what value the variable $o was returning. To see it in action just run the script and watch the console in the bottom section of SciTE (assuming you are using SciTE to code).

You will notice that when you open an image the value of $o is the full directory path including the file name (e.g. C:WindowsExample.jpg).Alternatively you could display a MsgBox that shows the same thing: e.g. MsgBox(0,'',$o) would show a MsgBox with the text C:WindowsExample.jpg. ConsoleWrite is just a bit less intrusive, but both are good for debugging :)

It's definitely good to utilise ConsoleWrite whilst writing code to make sure you are working with the right values! 

GDI Plus is a library that works with images/graphics - someone has worked hard to write all the code for us to use to make it simpler. For example you could spend hours working our how to get the image dimensions but someone has already done this and has written a function called _GDIPlus_ImageGetWidth()

I don't really know much more about GDI Plus to be honest, I usually use these forums to find examples and also look at Help files (very important!!) You can actually click on every one of those functions right here in the forum and it would take you to a page explaining what each one does. That's the best place to start to understand how each function works.

WinMove allows us to change the size of the GUI (and even move the GUI around if we need to), but in our case we just resize the GUI to fit the image.

Hope this helps :)

yea your post really make me understand many things ,, but in help file with autoit i feel that i cant understand the example that's why i ask u :/  ,, right ?  :

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