jlorenz1 Posted December 23, 2006 Share Posted December 23, 2006 (edited) I've simplified my problem. This script works and shows my problem. I've a picture with unknown width & height and I want to display a thumbnail of them. In the example and in the attachement I've created two different GIFs - a long one and a bold one. Both should be displayed correctly, but it doesn't work. It adapts only the frame not the pictures. Has anyone an idea or have found a solution for this basic problem? Thanks Johannes expandcollapse popup#include <GUIConstants.au3> Global $pic1 = 'long45x90.gif' Global $pic2 = 'bold90x45.gif' Global $Title = 'Thumbnail-Preview' Global $i = 1 GUICreate($Title, 130, 130, -1,-1, -1, $WS_EX_TOPMOST) $p = GUICtrlCreatePic (@ScriptDir & '\' & $pic1, 20, 5, 90, 90, -1, $SS_WHITEFRAME ) $b01 = GUICtrlCreateButton('Next', 60, 105, 60, 24) GUISetState (@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $b01 If $i = 1 Then $i = 2 $aSize = _GetImageSize(@ScriptDir & '\' & $pic2) GUICtrlSetImage ($p, @ScriptDir & '\' & $pic2) MsgBox(4160, 'Width & Height', 'width = ' & $aSize[0] & ' height = ' & $aSize[1]) ControlMove ($Title, '', $p, 20, 5 +45 - ($aSize[1]/2), $aSize[0] , $aSize[1] ) Else $i = 1 $aSize = _GetImageSize(@ScriptDir & '\' & $pic1) GUICtrlSetImage ($p, @ScriptDir & '\' & $pic1) MsgBox(4160, 'Width & Height', 'width = ' & $aSize[0] & ' height = ' & $aSize[1]) ControlMove ($Title, '', $p, 20 + 45 - ($aSize[0]/2), 5 , $aSize[0] , $aSize[1] ) EndIf EndSelect Wend ; These following functions are from Larry and working correctly ; Return Value an Array with the width and the height of an unknown picture ;=============================================================================== ; ; Description: Return JPEG, TIFF, BMP, PNG and GIF image size. ; Parameter(s): File name ; Requirement(s): None ; Return Value(s): On Success - array with width and height ; On Failure empty string and sets @ERROR: ; 1 - Not valid image or info not found ; Author(s): YDY (Lazycat) <mpc@nm.ru> ; Version: 1.0.00 ; Date: 18.08.2004 ; Note(s): None ; ;=============================================================================== Func _GetImageSize($file) Local $header = _FileReadAtOffsetHEX($file, 1, 8); Get header bytes Local $ident = StringSplit("FFD8 424D 89504E470D0A1A 4749463839 4749463837 4D4D 4949", " ") Local $size = "" For $ic = 1 To $ident[0] If StringInStr($header, $ident[$ic]) = 1 Then Select Case $ic = 1; JPEG $size = _GetJpegSize($file) Exitloop Case $ic = 2; BMP $size = _GetSimpleSize($file, 19, 23, 0) Exitloop Case $ic = 3; PNG $size = _GetSimpleSize($file, 19, 23, 1) Exitloop Case ($ic = 4) or ($ic = 5); GIF $size = _GetSimpleSize($file, 7, 9, 0) Exitloop Case ($ic = 6) or ($ic = 7); TIFF $size = _GetTIFFSize($file) Exitloop EndSelect Endif Next if not IsArray ($size) Then SetError(1) Return($size) EndFunc ;; Functions Func _GetSimpleSize($file, $xoff, $yoff, $ByteOrder) Local $size[2] $size[0] = _Dec(_FileReadAtOffsetHEX($file, $xoff, 2), $ByteOrder) $size[1] = _Dec(_FileReadAtOffsetHEX($file, $yoff, 2), $ByteOrder) Return ($size) EndFunc Func _GetJpegSize($file) Local $size[2] Local $fs, $pos = 3 $fs = FileGetSize($file) While $pos < $fs $data = _FileReadAtOffsetHEX ($file, $pos, 4) if StringLeft($data, 2) = "FF" then; Valid segment start if StringInStr("C0 C2 CA C1 C3 C5 C6 C7 C9 CB CD CE CF", StringMid($data, 3, 2)) then; Segment with size data $seg = _FileReadAtOffsetHEX ($file, $pos+5, 4) $size[1] = Dec(StringLeft($seg, 4)) $size[0] = Dec(StringRight($seg, 4)) Return($size) else $pos = $pos + Dec(StringRight($data, 4)) + 2 endif else exitloop endif Wend Return("") EndFunc Func _GetTIFFSize($file) Local $pos = 3, $ByteOrder = 0, $size[2] $id = _FileReadAtOffsetHEX ($file, 1, 2) If $id = "4D4D" then $ByteOrder = 1 $offset = _Dec(_FileReadAtOffsetHEX($file, 5, 4), $ByteOrder) + 1 $fields = _Dec(_FileReadAtOffsetHEX($file, $offset, 2), $ByteOrder) For $ic = 0 To $fields-1 $field = _FileReadAtOffsetHEX($file, $offset + 2 + 12 * $ic, 12) $tag = StringLeft($field, 4) If $ByteOrder Then $tag = StringRight($tag, 2) & StringLeft($tag, 2) Select Case $tag = "0001" $size[0] = _ParseField($file, $field, $ByteOrder) Case $tag = "0101" $size[1] = _ParseField($file, $field, $ByteOrder) EndSelect Next If ($size[0] = 0) or ($size[1] = 0) Then Return("") Return($size) Endfunc ;; Parse TIFF fields Func _ParseField($file, $tag, $ByteOrder) Local $type = _Dec(StringMid($tag, 5, 4), $ByteOrder) If $type < 5 Then Return (_Dec(StringRight($tag, 8), $ByteOrder)) Local $count = _Dec(StringMid($tag, 9, 8), $ByteOrder) Local $offset = _Dec(StringRight($tag, 8), $ByteOrder) Local $tStr = _FileReadAtOffsetHEX ($file, $offset, $count) Local $oStr = "" While StringLen($tStr) > 0 $oStr = $oStr & Chr(Dec(StringLeft($tStr, 2))) $tStr = StringTrimLeft($tStr, 2) WEnd Return($oStr) EndFunc Func _Dec($input, $ByteOrder) If $ByteOrder then Return(Dec($input)) Local $tStr = "" While StringLen($input) > 0 $tStr = $tStr & StringRight($input, 2) $input = StringTrimRight($input, 2) WEnd Return (Dec($tStr)) EndFunc Func _FileReadAtOffsetHEX ($file, $offset, $bytes) Local $tfile = FileOpen($file, 0) Local $tstr = "" FileRead($tfile, $offset-1) For $i = $offset To $offset + $bytes - 1 $tstr = $tstr & Hex(Asc(FileRead($tfile, 1)), 2) Next FileClose($tfile) Return ($tstr) Endfuncthumbnail.zip Edited December 23, 2006 by jlorenz1 Johannes LorenzBensheim, Germanyjlorenz1@web.de[post="12602"]Highlightning AutoIt Syntax in Notepad++ - Just copy in your Profile/application data/notepad++[/post] Link to comment Share on other sites More sharing options...
GaryFrost Posted December 23, 2006 Share Posted December 23, 2006 expandcollapse popupOpt("MustDeclareVars", 1) #include <GUIConstants.au3> #include <IE.au3> _Main() Func _Main() Local $pic1 = @ScriptDir & '\long45x90.gif' Local $pic2 = @ScriptDir & '\bold90x45.gif' Local $Title = 'Thumbnail-Preview' Local $i = 1 Local $pheight = 50, $pwidth = 50, $oIE, $GUIActiveX, $gif, $b01 $oIE = ObjCreate("Shell.Explorer.2") GUICreate("Embedded Web control Test", 130, 130) $gif = $pic1 $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, $pwidth, $pheight) _SetGifImage($GUIActiveX, $oIE, $gif, 0, 0, $pwidth, $pheight) $b01 = GUICtrlCreateButton('Next', 60, 105, 60, 24) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $b01 If $i = 1 Then $i = 2 $gif = $pic2 Else $i = 1 $gif = $pic1 EndIf _SetGifImage($GUIActiveX, $oIE, $gif, 0, 0, $pwidth, $pheight) EndSwitch WEnd EndFunc ;==>_Main Func _SetGifImage(ByRef $GUIActiveX, ByRef $oIE, ByRef $gif, $x = 0, $y = 0, $pwidth = 50, $pheight = 50) GUISetState(@SW_LOCK) GUICtrlDelete($GUIActiveX) _GetGifPixWidth_Height($gif, $pwidth, $pheight) $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, $pwidth, $pheight) $oIE.navigate ("about:blank") While _IEPropertyGet($oIE, "busy") Sleep(100) WEnd $oIE.document.body.background = $gif $oIE.document.body.scroll = "no" GUISetState(@SW_UNLOCK) EndFunc ;==>_SetGifImage Func _GetGifPixWidth_Height($s_gif, ByRef $pwidth, ByRef $pheight) If FileGetSize($s_gif) > 9 Then Local $sizes = FileRead($s_gif, 10) ConsoleWrite("Gif version: " & StringMid($sizes, 1, 6) & @LF) $pwidth = Asc(StringMid($sizes, 8, 1)) * 256 + Asc(StringMid($sizes, 7, 1)) $pheight = Asc(StringMid($sizes, 10, 1)) * 256 + Asc(StringMid($sizes, 9, 1)) ConsoleWrite($pwidth & " x " & $pheight & @LF) EndIf EndFunc ;==>_GetGifPixWidth_Height SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
jlorenz1 Posted December 23, 2006 Author Share Posted December 23, 2006 It is really great and it's works correctly, but I must say: The idea of an ActiveX Control is still new for me. In this area I'm a Newbie and your horicont is much, much wider. I have only one question : Is it possible to center all these previews? Because it is more "eye-friendly", if always the pictures are changing in their width and their height., Or is it too much work Johannes :"> Johannes LorenzBensheim, Germanyjlorenz1@web.de[post="12602"]Highlightning AutoIt Syntax in Notepad++ - Just copy in your Profile/application data/notepad++[/post] Link to comment Share on other sites More sharing options...
GaryFrost Posted December 23, 2006 Share Posted December 23, 2006 It is really great and it's works correctly, but I must say: The idea of an ActiveX Control is still new for me. In this area I'm a Newbie and your horicont is much, much wider. I have only one question : Is it possible to center all these previews? Because it is more "eye-friendly", if always the pictures are changing in their width and their height., Or is it too much work Johannes :"> Should be easy enough for you to change the code to make the way you want. for example: expandcollapse popupOpt("MustDeclareVars", 1) #include <GUIConstants.au3> #include <IE.au3> _Main() Func _Main() Local $pic1 = @ScriptDir & '\long45x90.gif' Local $pic2 = @ScriptDir & '\bold90x45.gif' Local $Title = 'Thumbnail-Preview' Local $i = 1, $win_width = 200, $win_height = 200 Local $pheight = 50, $pwidth = 50, $oIE, $GUIActiveX, $gif, $b01, $GUI $oIE = ObjCreate("Shell.Explorer.2") $GUI = GUICreate("Embedded Web control Test", $win_width, $win_height) $gif = $pic1 $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, $pwidth, $pheight) _SetGifImage($GUIActiveX, $oIE, $gif, 0, 0, $pwidth, $pheight, 1, $win_width, $win_height) $b01 = GUICtrlCreateButton('Next', 60, 175, 60, 24) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $b01 If $i = 1 Then $i = 2 $gif = $pic2 Else $i = 1 $gif = $pic1 EndIf _SetGifImage($GUIActiveX, $oIE, $gif, 0, 0, $pwidth, $pheight, 1, $win_width, $win_height) EndSwitch WEnd EndFunc ;==>_Main Func _SetGifImage(ByRef $GUIActiveX, ByRef $oIE, ByRef $gif, $x = 0, $y = 0, $pwidth = 50, $pheight = 50, $center = 0, $win_width = 500, $win_height = 500) GUISetState(@SW_LOCK) GUICtrlDelete($GUIActiveX) _GetGifPixWidth_Height($gif, $pwidth, $pheight) If $center Then $x = ($win_width/2) - ($pwidth/2) $y = ($win_height/2) - ($pheight/2) EndIf $GUIActiveX = GUICtrlCreateObj($oIE, $x, $y, $pwidth, $pheight) $oIE.navigate ("about:blank") While _IEPropertyGet($oIE, "busy") Sleep(100) WEnd $oIE.document.body.background = $gif $oIE.document.body.scroll = "no" GUISetState(@SW_UNLOCK) EndFunc ;==>_SetGifImage Func _GetGifPixWidth_Height($s_gif, ByRef $pwidth, ByRef $pheight) If FileGetSize($s_gif) > 9 Then Local $sizes = FileRead($s_gif, 10) ConsoleWrite("Gif version: " & StringMid($sizes, 1, 6) & @LF) $pwidth = Asc(StringMid($sizes, 8, 1)) * 256 + Asc(StringMid($sizes, 7, 1)) $pheight = Asc(StringMid($sizes, 10, 1)) * 256 + Asc(StringMid($sizes, 9, 1)) ConsoleWrite($pwidth & " x " & $pheight & @LF) EndIf EndFunc ;==>_GetGifPixWidth_Height SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. 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