Eluvatar Posted December 26, 2010 Share Posted December 26, 2010 the problem I'm having is that I cant add a jpg image to an image list and I'd love to know how, first off I'v writen a script to copy images from one place to another and once its done I want to display a preview of all the images in my gui along with there title, the amount of images can vary from 1 to 20 so it wont always fit in the gui and I want to put it into a list, also due to the fact that I'm copying from one place to another (preserving the file type) I cant change the images to bmp because of why I'm copying the images. note this works fine when I'v changed the image to a bmp but not as a jpg, I have also tried using GDIp to load the image and convert it into a bmp but I didnt know what I was doing so if someone could show me what too do that would be great, thanks #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #Include <GuiListView.au3> #include <ImageListConstants.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= Global $Form2 = GUICreate("Form2", 405, 296, 302, 218) GUISetOnEvent($GUI_EVENT_CLOSE, "Form2Close") Global $ListView1 = GUICtrlCreateListView("", 63, 31, 288, 222, $LVS_REPORT) GUICtrlSetOnEvent(-1, "ListView1Click") $ImageList1 = _GUIImageList_Create(150, 150) _GUIImageList_AddBitmap($ImageList1, "test.jpg") ConsoleWrite(_GUICtrlListView_SetImageList($listview1, $ImageList1, 1) & @CRLF) _GUICtrlListView_AddColumn($listview1, "Items", 222) _GUICtrlListView_AddItem($ListView1, "testimg", 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func Form2Close() Exit EndFunc Link to comment Share on other sites More sharing options...
Yashied Posted December 26, 2010 Share Posted December 26, 2010 expandcollapse popup#Include <GDIPlus.au3> #Include <GUIImageList.au3> #Include <GUIListView.au3> _GDIPlus_Startup() $hForm = GUICreate('MyGUI', 400, 400, 302, 218) $hListView = GUICtrlCreateListView('', 10, 10, 380, 380) _GUICtrlListView_AddColumn($hListView, 'Items', 200) $hImageList = _GUIImageList_Create(150, 160, 5, 1) _GUICtrlListView_SetImageList($hListView, $hImageList, 1) _GUIImageList_AddImage($hImageList, -1, @ScriptDir & '\test.jpg') _GUICtrlListView_AddItem($hListView, 'Test', 0) GUISetState() Do Until GUIGetMsg() = -3 Func _GUIImageList_AddImage($hWnd, $iIndex, $sFile) Local $Size = _GUIImageList_GetIconSize($hWnd) If (Not $Size[0]) Or (Not $Size[1]) Then Return -1 EndIf Local $W, $H, $hGraphic, $hPic, $hImage, $hIcon _GDIPlus_Startup() $hPic = _GDIPlus_ImageLoadFromFile($sFile) $W = _GDIPlus_ImageGetWidth($hPic) $H = _GDIPlus_ImageGetHeight($hPic) If ($W < 0) Or ($H < 0) Then _GDIPlus_Shutdown() Return -1 EndIf If $W < $H Then $W = $Size[0] * $W / $H $H = $Size[1] Else $H = $Size[1] * $H / $W $W = $Size[0] EndIf $hImage = DllCall($ghGDIPDll, 'int', 'GdipGetImageThumbnail', 'ptr', $hPic, 'int', $Size[0], 'int', $Size[1], 'ptr*', 0, 'ptr', 0, 'ptr', 0) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage[4]) _GDIPlus_GraphicsClear($hGraphic, 0) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hPic, ($Size[0] - $W) / 2, ($Size[1] - $H) / 2, $W, $H) $hIcon = DllCall($ghGDIPDll, 'int', 'GdipCreateHICONFromBitmap', 'ptr', $hImage[4], 'ptr*', 0) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage[4]) _GDIPlus_ImageDispose($hPic) _GDIPlus_Shutdown() If Not $hIcon[2] Then Return -1 EndIf $iIndex = _GUIImageList_ReplaceIcon($hWnd, $iIndex, $hIcon[2]) _WinAPI_DestroyIcon($hIcon[2]) Return $iIndex EndFunc ;==>_GUIImageList_AddImag NoNameCode 1 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Eluvatar Posted December 27, 2010 Author Share Posted December 27, 2010 Perfect thanks Yashied, and this will work the same in xp as it does in 7 and vista? also what would I need to change to have white bars instead of black on the top and bottom of my image preview? if thats not possible thats fine. Link to comment Share on other sites More sharing options...
Eluvatar Posted December 27, 2010 Author Share Posted December 27, 2010 The code works for me in Windows XP Pro SP3, but I don't know if it works "the same" without seeing how it works in Vista/7. I don't see any black bars, but trying changing this line from this: _GDIPlus_GraphicsClear($hGraphic, 0)to this. _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF) perfect, I looked for a color code like that but didnt see any and I didnt know what graphicsclear meant, thanks Deathbringer Link to comment Share on other sites More sharing options...
Eluvatar Posted January 7, 2011 Author Share Posted January 7, 2011 so I'v been using the code posted for a while, and it works great but the only problem is now that I cant remove items and images from the list here is some of the code;code to create the lists in the first place Global $ListView1 = GUICtrlCreateListView( "", 5, 80, 409, 242) $ImageList1 = _GUIImageList_Create(150, 150, 5, 1) _GUICtrlListView_SetImageList($listview1, $ImageList1, 1) _GUICtrlListView_AddColumn($listview1, "Images", 240) ;code to add images and there items _GUICtrlListView_AddItem($ListView1, $fileName, _GUIImageList_AddImage($fileName))I found if I create the listview with "_GUICtrlListView_Create" and not the normal I can remove items, (using "_GUICtrlListView_DeleteAllItems") except I cant figure out how to force the list to only display on the tab I want it too, (my gui has a tab design) so I use the normal way to create a listview but I cant figure out how to remove all the items from the list so I can add some more later. 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