vb.net - load image in picturebox quickly -
i have program shows previews of jpgs in small pictureboxes. loading of these images slow, , takes second each. because images big (8/9 mb). need load them quickly, example loading thumb of picture. avoid putting memory since there hundreds of pictures.
what advice on this?
thanks
you need resize pictures in advance.
creating tumbnails equally slow because need read whole file, before can start making tumbnail.
what is, windows, create tumbnail 'data base', store tumbs each picture. , use full size picture if needed.
so if have like,
picture001.jpg picture002.jpg picture003.jpg
create tumbs each one;
picture001.jpg picture001_tumb.jpg picture002.jpg picture002_tumb.jpg picture003.jpg picture003_tumb.jpg
so in loading of picuters detect, if _tumb.jpg there, if not create , store it. ofcourse, needs done in background worker, because need main app responsive...
you can use code, request icon windows shell;
imports system.runtime.interopservices imports system imports system.drawing imports system.drawing.imaging imports system.collections.generic imports system.text ' http://www.vbforums.com/showthread.php?617626-how-do-i-extract-a-256x256-image-out-of-an-icon&highlight=ishellitemimagefactory module getshellicon <flags()> _ public enum siigbf siigbf_resizetofit = 0 siigbf_biggersizeok = 1 siigbf_memoryonly = 2 siigbf_icononly = 4 siigbf_thumbnailonly = 8 siigbf_incacheonly = 16 end enum public enum sigdn uinteger normaldisplay = 0 parentrelativeparsing = &h80018001ui parentrelativeforaddressbar = &h8001c001ui desktopabsoluteparsing = &h80028000ui parentrelativeediting = &h80031001ui desktopabsoluteediting = &h8004c000ui filesyspath = &h80058000ui url = &h80068000ui end enum <comimportattribute(), guidattribute("bcc18b79-ba16-442f-80c4-8a59c30c463b"), interfacetypeattribute(cominterfacetype.interfaceisiunknown)> _ public interface ishellitemimagefactory sub getimage(byval size size, byval flags siigbf, byref phbm intptr) end interface <comimport()> <guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")> <interfacetype(cominterfacetype.interfaceisiunknown)> _ public interface ishellitem sub bindtohandler(byval pbc intptr, <marshalas(unmanagedtype.lpstruct)> byval bhid guid, <marshalas(unmanagedtype.lpstruct)> byval riid guid, byref ppv intptr) sub getparent(byref ppsi ishellitem) sub getdisplayname(byval sigdnname sigdn, byref ppszname intptr) sub getattributes(byval sfgaomask uint32, byref psfgaoattribs uint32) sub compare(byval psi ishellitem, byval hint uint32, byref piorder integer) end interface <dllimport("shell32.dll", charset:=charset.unicode, preservesig:=false)> _ public sub shcreateitemfromparsingname(<marshalas(unmanagedtype.lpwstr)> byval pszpath string, byval pbc intptr, <marshalas(unmanagedtype.lpstruct)> byval riid guid, <marshalas(unmanagedtype.interface, iidparameterindex:=2)> byref ppv ishellitem) end sub <structlayout(layoutkind.sequential)> _ public structure size public cx integer public cy integer public sub new(byval cx integer, byval cy integer) me.cx = cx me.cy = cy end sub end structure public function getshellicon(byval path string, mysiigbf siigbf, optional byval width integer = 256, optional byval height integer = 256) bitmap dim ppsi ishellitem = nothing dim hbitmap intptr = intptr.zero dim uuid new guid("43826d1e-e718-42ee-bc55-a1e261c37bfe") dim bs bitmap shcreateitemfromparsingname(path, intptr.zero, uuid, ppsi) directcast(ppsi, ishellitemimagefactory).getimage(new size(width, height), mysiigbf, hbitmap) bs = system.drawing.bitmap.fromhbitmap(hbitmap) bs.maketransparent(color.black) return bs end function end module
Comments
Post a Comment