Jump to content
Sign in to follow this  
ileandros

Autoit read .TGA files/ photos

Recommended Posts

ileandros

Hello there,

I have a simple image viewer.

It read urls from IE given, gets all the images and show them.

My only problem is that it doesnt read the .TGA images. Is it able to make it read the .TGA images even if i dont program required installed for .TGA files?

Actually i know that it is possible since i have a simillar program in java but is it possible to make that in AutoIt???

Thanks!


I feel nothing.It feels great.

Share this post


Link to post
Share on other sites
ileandros

Any ideas people???

Bump


I feel nothing.It feels great.

Share this post


Link to post
Share on other sites
ileandros

Read and show...It's a image viewer. You got any ideas???


I feel nothing.It feels great.

Share this post


Link to post
Share on other sites
BrewManNH

I don't think that Windows can view TGA files natively, so I don't think you'll be able to do it in AutoIt without some sort of external program being used.


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

Share this post


Link to post
Share on other sites
Blue_Drache

Brew is correct. I had to install an extension to view TGA natively in Windows' Icon view and to be able to build thumbs for them.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites
ileandros

I know that. As i already said that i have a image viewer in java witch does read/show the .TGA.

But since there is not way in AutoIt fine.

Thanks

Edited by ileandros

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites
AdmiralAlkex

SDL_image can read TGA.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include "SDL.au3"
#include "SDL_image.au3"

;Select file
$sRet = FileOpenDialog("Select .tga file to open", "", "TARGA files (*.tga)")
If @error Then Exit 0* ConsoleWrite("blah blah" & @LF)

;Init stuff
_SDL_Init($_SDL_INIT_VIDEO)
_SDL_Init_image(@ScriptDir & "")

;Load picture
$pImage = _IMG_Load($sRet)

;Get size
$tImage = DllStructCreate($tagSDL_SURFACE, $pImage)
$iWidth = DllStructGetData($tImage, "w")
$iHeight = DllStructGetData($tImage, "h")

;Something to display on
$pScreen = _SDL_GuiCreate("Some title", $iWidth, $iHeight, 0, 0)

;Copy to screen
_SDL_BlitSurface($pImage, 0, $pScreen, 0)

;Show
_SDL_Flip($pScreen)

;Close window as normal
While 1
    Sleep(10)
WEnd

Share this post


Link to post
Share on other sites
ileandros

Seems cool but i got a problem. I got a problem with dl.

Internet Explorer cannot display the webpage...

Is this only my problem or is there a problem with the link???


I feel nothing.It feels great.

Share this post


Link to post
Share on other sites
ileandros

Talking about SDL UDF


I feel nothing.It feels great.

Share this post


Link to post
Share on other sites
AdmiralAlkex

It seems whatever host I choose it go down in a year or so ;)

MVP's has more space, so now I was able to attach the zip to the post directly. You can download from there now.

Share this post


Link to post
Share on other sites
ileandros

Ok fine now. The script above seems to work fine. But after choosing a image (.TGA) at the OpenDialog i got a Autoit3.exe System Error:

"The program can't starte because SDL.dll is missing from ur computer.

Try reinstalling the program to fix this problem."

Does it run to you???

After that i got an error in the ConsoleWrite:

C:UsersLeandroDesktoplean.au3UDFSDL_image.au3 (48) : ==> Subscript used with non-Array variable.:

$Struct = DllStructCreate("ubyte;ubyte;ubyte", $pTemp[0])

$Struct = DllStructCreate("ubyte;ubyte;ubyte", $pTemp^ ERROR


I feel nothing.It feels great.

Share this post


Link to post
Share on other sites
AdmiralAlkex

Did you copy the dll to the script folder? That message means that the dll is missing.

You need

SDL.au3

SDL.dll

SDL_image.au3

SDL_image.dll

at the very least.

It runs for me.

Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites
ProgAndy

You can also use FreeImage. These snippets are in C, but the AutoIt-code should be similar. When you have the HBITMAP, use

Edit: Here is an example:

#AutoIt3Wrapper_usex64=n
#include<WinAPI.au3>
#include<FreeImage.au3>
#include <GUIConstants.au3>

; modify these variables
Global Const $sFreeImageDLL = "E:UDFFreeImageFreeImage.dll"
Global Const $sTIFF_File = @ScriptDir & "test.tif"

_FreeImage_LoadDLL($sFreeImageDLL)

#region - GUI Create
GUICreate('Display', 400, 400)
$iPic = GUICtrlCreatePic("", 0, 0, 400, 400)
GUISetState()
#endregion


; Load image, create thumbnail, maximum 400x400px
$pDIBOrg = _FreeImage_Load($FIF_TIFF, $sTIFF_File);
$pDIB = _FreeImage_MakeThumbnail($pDIBOrg, 400)
_FreeImage_Unload($pDIBOrg)

; create windows HBITMAP for picture control
$hDC = _WinAPI_GetDC(GUICtrlGetHandle($iPic))
$hBitmap = DllCall('gdi32.dll', 'ptr', 'CreateDIBitmap', 'hwnd', $hDC, 'ptr', _FreeImage_GetInfoHeader($pDIB), 'dword', 0x04, 'ptr', _FreeImage_GetBits($pDIB), 'ptr', _FreeImage_GetInfo($pDIB), "uint", 0)
$hBitmap = $hBitmap[0]
_WinAPI_ReleaseDC(GUICtrlGetHandle($iPic), $hDC)

; Free FreeImage image
_FreeImage_Unload($pDIB);

; set HBITMAP to control
_GUICtrlStatic_SetImage($iPic, $hBitmap)


#region - GUI SelectLoop
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd
#endregion

; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlStatic_SetImage
; Description ...: Sets a HBITMAP to a static control like image or label
; Syntax.........: _GUICtrlStatic_SetImage($iCtrlId, $hBitmap)
; Parameters ....: $iCtrlId  - CtrlId or handle of Control in the current process
;                 $hBitmap  - Pointer top Windows HBITMAP
; Return values .: Success    - 1
;                 Failure     - 0 and set @error:
;                 |1  - invalid $pSource
;                 |1  - invalid $pSource
; Author ........: ProgAndy, Zedna
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GUICtrlStatic_SetImage($iCtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    If IsHWnd($iCtrlId) Then
        If WinGetProcess($iCtrlId) <> @AutoItPID Then Return SetError(1,0,0)
    Else
        $iCtrlId = GUICtrlGetHandle($iCtrlId)
        If Not $iCtrlId Then Return SetError(2,0,0)
    EndIf
    ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE)
    If @error Then Return SetError(3, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(4, 0, 0)
    Local $oldBmp = DllCall("user32.dll", "handle", "SendMessageW", "hwnd", $iCtrlId, "int", $STM_SETIMAGE, "wparam", $IMAGE_BITMAP, "handle", $hBitmap)
    If @error Then Return SetError(5, 0, 0)
    If $oldBmp[0] Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
ileandros

AdmiralAlkex,

yes i copied it at the script folder. I also tryied to delete and dl it again but still same problem.

Are you sure that at the dl package are everything required?Saying because u have problem with the link.I dont know whats wrong.

After that message it shows this error in the console of scite

C:UsersLeandroDesktoplean.au3UDFSDL_image.au3 (48) : ==> Subscript used with non-Array variable.:

$Struct = DllStructCreate("ubyte;ubyte;ubyte", $pTemp[0])

$Struct = DllStructCreate("ubyte;ubyte;ubyte", $pTemp^ ERROR

Edit: All the examples works fine though.....

Edited by ileandros

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites
ileandros

You can also use FreeImage. These snippets are in C, but the AutoIt-code should be similar. When you have the HBITMAP, use

Edit: Here is an example:

#AutoIt3Wrapper_usex64=n
#include<WinAPI.au3>
#include<FreeImage.au3>
#include <GUIConstants.au3>

; modify these variables
Global Const $sFreeImageDLL = "E:UDFFreeImageFreeImage.dll"
Global Const $sTIFF_File = @ScriptDir & "test.tif"

_FreeImage_LoadDLL($sFreeImageDLL)

#region - GUI Create
GUICreate('Display', 400, 400)
$iPic = GUICtrlCreatePic("", 0, 0, 400, 400)
GUISetState()
#endregion


; Load image, create thumbnail, maximum 400x400px
$pDIBOrg = _FreeImage_Load($FIF_TIFF, $sTIFF_File);
$pDIB = _FreeImage_MakeThumbnail($pDIBOrg, 400)
_FreeImage_Unload($pDIBOrg)

; create windows HBITMAP for picture control
$hDC = _WinAPI_GetDC(GUICtrlGetHandle($iPic))
$hBitmap = DllCall('gdi32.dll', 'ptr', 'CreateDIBitmap', 'hwnd', $hDC, 'ptr', _FreeImage_GetInfoHeader($pDIB), 'dword', 0x04, 'ptr', _FreeImage_GetBits($pDIB), 'ptr', _FreeImage_GetInfo($pDIB), "uint", 0)
$hBitmap = $hBitmap[0]
_WinAPI_ReleaseDC(GUICtrlGetHandle($iPic), $hDC)

; Free FreeImage image
_FreeImage_Unload($pDIB);

; set HBITMAP to control
_GUICtrlStatic_SetImage($iPic, $hBitmap)


#region - GUI SelectLoop
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd
#endregion

; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlStatic_SetImage
; Description ...: Sets a HBITMAP to a static control like image or label
; Syntax.........: _GUICtrlStatic_SetImage($iCtrlId, $hBitmap)
; Parameters ....: $iCtrlId  - CtrlId or handle of Control in the current process
;                 $hBitmap  - Pointer top Windows HBITMAP
; Return values .: Success    - 1
;                 Failure     - 0 and set @error:
;                 |1  - invalid $pSource
;                 |1  - invalid $pSource
; Author ........: ProgAndy, Zedna
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GUICtrlStatic_SetImage($iCtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    If IsHWnd($iCtrlId) Then
        If WinGetProcess($iCtrlId) <> @AutoItPID Then Return SetError(1,0,0)
    Else
        $iCtrlId = GUICtrlGetHandle($iCtrlId)
        If Not $iCtrlId Then Return SetError(2,0,0)
    EndIf
    ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE)
    If @error Then Return SetError(3, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(4, 0, 0)
    Local $oldBmp = DllCall("user32.dll", "handle", "SendMessageW", "hwnd", $iCtrlId, "int", $STM_SETIMAGE, "wparam", $IMAGE_BITMAP, "handle", $hBitmap)
    If @error Then Return SetError(5, 0, 0)
    If $oldBmp[0] Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc

Nice work ;)

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites
AdmiralAlkex

AdmiralAlkex,

yes i copied it at the script folder. I also tryied to delete and dl it again but still same problem.

Are you sure that at the dl package are everything required?Saying because u have problem with the link.I dont know whats wrong.

After that message it shows this error in the console of scite

C:\Users\Leandro\Desktop\lean.au3\UDF\SDL_image.au3 (48) : ==> Subscript used with non-Array variable.:

$Struct = DllStructCreate("ubyte;ubyte;ubyte", $pTemp[0])

$Struct = DllStructCreate("ubyte;ubyte;ubyte", $pTemp^ ERROR

Edit: All the examples works fine though.....

Well, the UDF do has some "issues" (I have been wanting to rewrite it complete for some time), but this problem happens much more often than i expect.

Does it work if you put it in the same folder as the examples?

Try changing the SDL_init line to _SDL_Init($_SDL_INIT_VIDEO, @ScriptDir & "\") (or wherever you put the sdl.dll)

Also, could you post the complete output from the console? That way I can try and reproduce the error on the same Windows and AutoIt you have...

Share this post


Link to post
Share on other sites
ileandros

That fixed it!!!

Now works like a charm. I already have a program installed in my cpu for .TGA files so i dont know if it will work without it but i guess it will.

Thanks


I feel nothing.It feels great.

Share this post


Link to post
Share on other sites
AdmiralAlkex

You can also use FreeImage. These snippets are in C, but the AutoIt-code should be similar. When you have the HBITMAP, use

Edit: Here is an example:

Interesting example and UDF. Using that and the gdi+ to sdl example I made this:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <FreeImage.au3>
#Include "SDL.au3"
#Include "SDL_gfx.au3"

#region ;Examples
$hWnd1 = GUICreate("Testing _BitmapToSurface", 457, 266, 0, 0)
GUISetState()

EnvSet("SDL_WINDOWID", $hWnd1)
_SDL_Init($_SDL_INIT_VIDEO, @ScriptDir & "")
_FreeImage_LoadDLL(@ScriptDir & "FreeImage.dll")
_SDL_Startup_gfx(@ScriptDir & "")

$pScreen = _SDL_SetVideoMode(457, 266, 32, $_SDL_SWSURFACE)

$pDIBOrg = _FreeImage_Load($FIF_PNG, @ScriptDir & "SDL_logo.png")

_BlitFreeImageToSurface($pDIBOrg, $pScreen)
_SDL_Flip($pScreen)

; Free FreeImage image
_FreeImage_Unload($pDIBOrg);

Do
Until GUIGetMsg() = -3

_SDL_Quit()
#endregion

#region ;_BlitFreeImageToSurface
Func _BlitFreeImageToSurface($pDIB, $pSurface)
    $iWidth = _FreeImage_GetWidth($pDIB)
    $iHeight = _FreeImage_GetHeight($pDIB)

    $pTemp = _SDL_CreateRGBSurfaceFrom(_FreeImage_GetBits($pDIB), $iWidth, $iHeight, _FreeImage_GetBPP($pDIB), _FreeImage_GetPitch($pDIB), 0, 0, 0, 0)
    $pRotated = _SDL_rotozoomSurfaceXY($pTemp, 360, 1, -1, 0) ;Flip image. FreeImage stores upside down evidently...

    _SDL_BlitSurface($pRotated, _SDL_Rect_Create(0, 1, $iWidth, $iHeight), $pSurface, 0) ;Remove black line at top
    _SDL_FreeSurface($pRotated)
    _SDL_FreeSurface($pTemp)
EndFunc
#endregion

Had to mess around a little to flip the image and remove an extra black line but it seems to work fine.

That fixed it!!!

Now works like a charm. I already have a program installed in my cpu for .TGA files so i dont know if it will work without it but i guess it will.

Thanks

No other programs are needed, only the dll. It's standalone like AutoIt.

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  

×