Jump to content
Sign in to follow this  
gumbitha

Showing a png image

Recommended Posts

gumbitha

Hey, I'm back. I'm trying to have there be a preview window for images in my GUI. Unfortunately, PNG support is a must, and that is exactly what AutoIt does not want to do, I know there is some way using the GDIPlus library, but everything I do seems to fail. Could someone help me?

(If you are curious, this GUI will eventually be outputting commands to another program, but for now it just says what the converted filetype will be muttley. )

#include <GUIConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>





#Region ### START Koda GUI section ### Form=
$InputForm = GUICreate("Form1", 625, 212, 193, 128)
$Label1 = GUICtrlCreateLabel("This is a test of the input system", 16, 8, 154, 17)
$Input = GUICtrlCreateInput("Input file here...", 16, 48, 441, 21)
$InputBrowse = GUICtrlCreateButton("Browse", 464, 48, 75, 25, 0)
$Group1 = GUICtrlCreateGroup("", 469, 71, 134, 141)

$TXMPrev = GUICtrlCreatePic("", 472, 80, 128, 128)
$Output = GUICtrlCreateInput("Output filename would go here", 16, 144, 433, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
$Execute = GUICtrlCreateButton("Do it!", 184, 104, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$InputPath = "C:\none"
While 1
$nMsg = GUIGetMsg()
Select
    
Case $nMsg = $GUI_EVENT_CLOSE
    
Exit

Case $nMsg = $InputBrowse
    $InputPath = FileOpenDialog("Select file:", $InputPath, "Onisplit Compatible Files (*.aif;*.dae;*.dds;*.obj;*.png;*.tga;*.txt;*.wav;*.xml;*.xmp)|M3GM\TRBS (*.obj;*.dae)|ONCC\TRAC\TRAM (*.xml)|SNDD (*.wav;*.aif)|SUBT (.txt)|TXMP (*.dds;*.xmp;*.png;*.tga)|(*.*)")
    If @error Then ContinueLoop
    GUICtrlSetData($Input, $InputPath)
Case $nMsg = $Execute
    filetypechange()
EndSelect
WEnd

Func filetypechange()
$PathArray = StringSplit($InputPath, "\")
$InputFile = $PathArray[$PathArray[0]]
$InputExt = StringRight($InputFile,3)
    
Switch $InputExt
    Case "txt"
    $OniType = "SUBT"
    Case "xml" 
        $OniType = "ONCC\TRAC\TRAM"
    Case "obj"
        $OniType = "M3GM\TRBS"
    Case "dae"
        $OniType = "M3GM\TRBS"
    Case "DDS"
        $OniType = "TXMP"
    Case "XMP"
        $OniType = "TXMP"
    Case "PNG"
        $OniType = "TXMP"   
    Case "TGA"
        $OniType = "TXMP"
    Case "wav"
        $OniType = "SNDD"
    Case "aif"
        $OniType = "SNDD"
    Case Else
        $OniType = "Null"
    EndSwitch

If $OniType = "TXMP" Then
        If $InputExt = "png" Then
    ;What goes here?
    Else
        GUICtrlSetImage($TXMPrev, $InputPath)
    EndIf
EndIf
If NOT($OniType = "Null") Then
        GUICtrlSetData($Output, $OniType)
    Else
        GUICtrlSetData($Output, "You can't input this type of file!" &  " (." & $InputExt & ")");   
EndIf




EndFunc

Share this post


Link to post
Share on other sites
Cha0sBG

i think autoit is not able to show PGN format images :S i have tryed


Have Questions About GUI (Graphical User Interface) ? Post Them Here :GUI Help And Support ForumHave Questions About General AutoIt ? Post Them Here : General Help And Support ForumNew To AutoIt ? Be Shure To Check Out The FaQ's (Frequently Asked Questions) Or FaQ ยน There You May Find Great Help That Will Guide You True The Wonderful Programming Language AutoItOthere Good Place To Get Some Knolage Of AutoIt Is The Example Script ForumNotice A Bug ? Please Go And Report it At Bug Report Section And Help The Devolepers Of AutoIt Update And Fix The Programming LanguageWant To Thank The People For This Great Forum And Programming Language ? Then DonateWhen You Found The Answer Your Looking For Please Add [Resolved] To The Thread's Name That Will Show Otheres That You Have Found What Your Looking For And They Whount Have To Enter The Thread.

Share this post


Link to post
Share on other sites
gumbitha

Heh. Got it figured out. I'll post what I got in a few minutes.

I just wish I could make the png files scale. If anyone knows CSS, I could use some help on that small part. muttley

Open the GUI, Browse to any png file in your computer, click "Do it!" and it is previewed. Now go to any other file (.txt works, other files too, if you choose *.* on the dropdown menu) and it goes away. :)

#include <GUIConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <IE.au3> 



$IE = _IECreateEmbedded ()



#Region ### START Koda GUI section ### Form=
$InputForm = GUICreate("Form1", 625, 212, 193, 128)
$Label1 = GUICtrlCreateLabel("This is a test of the input system", 16, 8, 154, 17)
$Input = GUICtrlCreateInput("Input file here...", 16, 48, 441, 21)
$InputBrowse = GUICtrlCreateButton("Browse", 464, 48, 75, 25, 0)
$Group1 = GUICtrlCreateGroup("", 469, 71, 134, 141)

$TXMPrev = GUICtrlCreateObj($IE, 472, 80, 128, 128)
GUICtrlSetState(-1, $GUI_HIDE)
$Output = GUICtrlCreateInput("Output filename would go here", 16, 144, 433, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
$Execute = GUICtrlCreateButton("Do it!", 184, 104, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

  ;  $IE.navigate("about:blank")
 ;   $IE.document.Write(GetPng("C:\Users\Jay Geise\Pictures\sfu semifinal.png"))

    $IE.document.body.scroll = "no"
   $IE.navigate("about:blank")

$InputPath = "C:\none"
While 1
$nMsg = GUIGetMsg()
Select
    
Case $nMsg = $GUI_EVENT_CLOSE
    
Exit

Case $nMsg = $InputBrowse
    $InputPath = FileOpenDialog("Select file:", $InputPath, "Onisplit Compatible Files (*.aif;*.dae;*.dds;*.obj;*.png;*.tga;*.txt;*.wav;*.xml;*.xmp)|M3GM\TRBS (*.obj;*.dae)|ONCC\TRAC\TRAM (*.xml)|SNDD (*.wav;*.aif)|SUBT (.txt)|TXMP (*.dds;*.xmp;*.png;*.tga)|(*.*)")
    If @error Then ContinueLoop
    GUICtrlSetData($Input, $InputPath)
Case $nMsg = $Execute
    filetypechange()
EndSelect
WEnd
Func GetPng($file)
    ;this is really only necessary for transparent images.  IE has to use a filter to display them.
    Local $temp
    If FileExists($file) Then
    Local $s_html = ""
        $temp = "file:///" & StringReplace($file, "\", "/")
        $temp = StringReplace($temp, " ", "%20")
       $s_html=$s_html&'<?xml version="1.0" encoding="UTF-8"?><html><head></head><body scroll="no">'
        $s_html=$s_html&'<!--[if gte IE 5.5]><![if lt IE 7]><style type="text/css">'
        $s_html=$s_html&'#Image1 img{ filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0); }#Image1 { display: inline-block; }'
        $s_html=$s_html&'#Image1 { filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' & $temp & '"); }'
        $s_html=$s_html&'</style><![endif]><![endif]-->'
        $s_html=$s_html& '<img id="Image1" style="position:absolute;top:0;left:0;" src="' & $temp & '" left="0" top="0" width="128" /></body></html>'
        Return $s_html
    EndIf
EndFunc
Func filetypechange()
$PathArray = StringSplit($InputPath, "\")
$InputFile = $PathArray[$PathArray[0]]
$InputExt = StringRight($InputFile,3)
    
Switch $InputExt
    Case "txt"
    $OniType = "SUBT"
    Case "xml" 
        $OniType = "ONCC\TRAC\TRAM"
    Case "obj"
        $OniType = "M3GM\TRBS"
    Case "dae"
        $OniType = "M3GM\TRBS"
    Case "DDS"
        $OniType = "TXMP"
    Case "XMP"
        $OniType = "TXMP"
    Case "PNG"
        $OniType = "TXMP"   
    Case "TGA"
        $OniType = "TXMP"
    Case "wav"
        $OniType = "SNDD"
    Case "aif"
        $OniType = "SNDD"
    Case Else
        $OniType = "Null"
    EndSwitch

If $OniType = "TXMP" Then
   $IE.document.Write(GetPng($InputPath))
GUICtrlSetState($TXMPrev, $GUI_SHOW)
Else
    GUICtrlSetState($TXMPrev, $GUI_HIDE)
EndIf
If NOT($OniType = "Null") Then
        GUICtrlSetData($Output, $OniType)
        
    Else
        GUICtrlSetData($Output, "You can't input this type of file!" &  " (." & $InputExt & ")");   
EndIf
EndFunc
Edited by gumbitha

Share this post


Link to post
Share on other sites
gumbitha

Thanks. But the way I have it now works just fine :P I understand exactly what is going on.

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.