3

我有一个程序可以在小图片框中显示 jpg 的预览。这些图像的加载速度很慢,每个图像几乎需要一秒钟。那是因为图像很大(8/9 mB)。我需要快速加载它们,例如通过加载图片的拇指。我想避免将所有内容都放入内存中,因为可能有数百张图片。

你对此有何建议?

谢谢

4

1 回答 1

1

您需要提前调整图片大小。

创建缩略图会同样慢,因为您需要阅读整个文件,然后才能开始制作缩略图。

您可以做的是,就像 Windows 一样,创建一个缩略图“数据库”,您可以在其中存储每张图片的 tumb。并且仅在需要时使用全尺寸图片。

所以如果你喜欢,

picture001.jpg
picture002.jpg
picture003.jpg

为每个人创建 tumbs;

picture001.jpg
picture001_tumb.jpg
picture002.jpg
picture002_tumb.jpg
picture003.jpg
picture003_tumb.jpg

因此,在加载图片时检测,如果_tumb.jpg 存在,则创建并存储它。当然,这需要在后台工作人员中完成,因为您需要您的主应用程序来响应......

您也可以使用此代码从 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 As 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 As SIZE, ByVal flags As SIIGBF, ByRef phbm As IntPtr)
    End Interface

    <ComImport()> <Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")>     <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
    Public Interface IShellItem
        Sub BindToHandler(ByVal pbc As IntPtr, <MarshalAs(UnmanagedType.LPStruct)>     ByVal bhid As Guid, <MarshalAs(UnmanagedType.LPStruct)> ByVal riid As Guid, ByRef ppv As     IntPtr)
        Sub GetParent(ByRef ppsi As IShellItem)
        Sub GetDisplayName(ByVal sigdnName As SIGDN, ByRef ppszName As IntPtr)
        Sub GetAttributes(ByVal sfgaoMask As UInt32, ByRef psfgaoAttribs As UInt32)
        Sub Compare(ByVal psi As IShellItem, ByVal hint As UInt32, ByRef piOrder As     Integer)
    End Interface

    <DllImport("shell32.dll", CharSet:=CharSet.Unicode, PreserveSig:=False)> _
    Public Sub SHCreateItemFromParsingName(<MarshalAs(UnmanagedType.LPWStr)> ByVal     pszPath As String, ByVal pbc As IntPtr, <MarshalAs(UnmanagedType.LPStruct)> ByVal riid As     Guid, <MarshalAs(UnmanagedType.Interface, IidParameterIndex:=2)> ByRef ppv As IShellItem)
    End Sub

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure SIZE
        Public cx As Integer
        Public cy As Integer
        Public Sub New(ByVal cx As Integer, ByVal cy As Integer)
            Me.cx = cx
            Me.cy = cy
        End Sub
    End Structure

    Public Function GetShellIcon(ByVal Path As String, MySIIGBF As SIIGBF, Optional ByVal Width As Integer = 256, Optional ByVal Height As Integer = 256) As Bitmap

        Dim ppsi As IShellItem = Nothing
        Dim hbitmap As IntPtr = IntPtr.Zero
        Dim uuid As New Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")

        Dim bs As 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
于 2013-08-16T08:35:08.390 回答