• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1082
  • Last Modified:

.net IExtractImage... one more time "Where is the .Net GURU"


Here is my code snipit.  of course it does not work (why would I be asking for help.)
All I want to do is get the thumbnail of the file slected from my list box and display it
with my image control.  HELP....

 Private Sub lstDgnFiles_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstDgnFiles.SelectedIndexChanged
        Try
            Dim myCurFile As FileInfo
            Dim myShellImg As New IShellFolderEx_TLB.FOLDERSETTINGS
            Dim myNextTry As IExtractImage2Lib.IExtractImage

            Dim myother As IExtractImage2Lib.IUnknown
            Dim trythis As VariantType  '
            Dim ipld As Integer


            myCurFile = lstDgnFiles.SelectedItem.FullName.ToString


            trythis = myNextTry.GetLocation(myCurFile.FullName.ToString, 200, 500, Nothing, 20, 200)
            imgPreview.Image = myNextTry.Extract(trythis)
0
sherrick123
Asked:
sherrick123
  • 5
  • 5
  • 4
  • +1
1 Solution
 
iboutchkineCommented:
try this

Public Class frmMain
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents picThumb As System.Windows.Forms.PictureBox
    Friend WithEvents btnGenerateThumbNail As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.picThumb = New System.Windows.Forms.PictureBox
        Me.btnGenerateThumbNail = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'picThumb
        '
        Me.picThumb.Location = New System.Drawing.Point(45, 12)
        Me.picThumb.Name = "picThumb"
        Me.picThumb.Size = New System.Drawing.Size(166, 128)
        Me.picThumb.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage
        Me.picThumb.TabIndex = 0
        Me.picThumb.TabStop = False
        '
        'btnGenerateThumbNail
        '
        Me.btnGenerateThumbNail.Location = New System.Drawing.Point(45, 156)
        Me.btnGenerateThumbNail.Name = "btnGenerateThumbNail"
        Me.btnGenerateThumbNail.Size = New System.Drawing.Size(168, 40)
        Me.btnGenerateThumbNail.TabIndex = 1
        Me.btnGenerateThumbNail.Text = "Create Thumbnail"
        '
        'frmMain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(258, 208)
        Me.Controls.Add(Me.btnGenerateThumbNail)
        Me.Controls.Add(Me.picThumb)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.Name = "frmMain"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Generate Thumbnail Test"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub btnGenerateThumbNail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerateThumbNail.Click
        ' NOTE*** This code does not use proper error handling.

        ' Create the variables to hold the origional image and it's thumbnail.
        Dim objImage As New Bitmap(Application.StartupPath & "\testimage.jpg")
        Dim objThumbnail As Bitmap

        ' Create the thumbnail image and assign it to the objThumbnail variable.
        objThumbnail = objImage.GetThumbnailImage(130, 100, Nothing, Nothing)

        ' Display the thumbnail in a picturebox.
        Me.picThumb.Image = objThumbnail

        ' Now lets save the the thumbnail to C:\testthumbnail.jpg
        objThumbnail.Save("C:\temp\thumbnail.jpg", Imaging.ImageFormat.Jpeg)

    End Sub
End Class
0
 
Bob LearnedCommented:
Ooh, there's one of the top .NET gurus right there :))

Bob
0
 
sherrick123Author Commented:

Does this only work for Image Files.  I want to get the same image as what the Windows Explorer displays.
That is why I am sure I have to use the IExtractImage function.

Hope this explains what I am wanting.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
iboutchkineCommented:
if you want to extract image from executable file, there are plenty of programs like that on the internet. Search google.
0
 
sherrick123Author Commented:

Nope that is not what I want to do.  I want to get the image from ANY file that can display a thumbnail.
in Window Explorer.  In my form I am only displaying a certain file.  When the user pics that file I want it to display the image of that file.  Such as windows explorer does.  I am just sure that I have to use IExtractImage BUT there is no .net examples.  I don't know C++ and the VB 6 example that I found doesn't work in .net.  I have to develope this in .net

0
 
iboutchkineCommented:
try  this. It will give you file assosiated icons

Add a listView control, a button control, and an imageList control to the form.
The default names are ListView1, Button1, and ImageList1, respectively.
In the Properties window of Button1, set the button text to Select a File


Imports System.Runtime.InteropServices

Public Class Form1
    Inherits System.Windows.Forms.Form
    Private Structure SHFILEINFO
        Public hIcon As IntPtr            ' : icon
        Public iIcon As Integer           ' : icondex
        Public dwAttributes As Integer    ' : SFGAO_ flags
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
        Public szDisplayName As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
        Public szTypeName As String
    End Structure

    Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _
            (ByVal pszPath As String, _
             ByVal dwFileAttributes As Integer, _
             ByRef psfi As SHFILEINFO, _
             ByVal cbFileInfo As Integer, _
             ByVal uFlags As Integer) As IntPtr

    Private Const SHGFI_ICON = &H100
    Private Const SHGFI_SMALLICON = &H1
    Private Const SHGFI_LARGEICON = &H0    ' Large icon
    Private nIndex = 0


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.ListView1 = New System.Windows.Forms.ListView
        Me.Button1 = New System.Windows.Forms.Button
        Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
        Me.SuspendLayout()
        '
        'ListView1
        '
        Me.ListView1.Location = New System.Drawing.Point(0, 0)
        Me.ListView1.Name = "ListView1"
        Me.ListView1.Size = New System.Drawing.Size(720, 160)
        Me.ListView1.TabIndex = 0
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(8, 168)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Select File"
        '
        'ImageList1
        '
        Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
        Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(724, 314)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.ListView1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim hImgSmall As IntPtr  'The handle to the system image list.
        Dim hImgLarge As IntPtr  'The handle to the system image list.
        Dim fName As String      'The file name to get the icon from.
        Dim shinfo As SHFILEINFO
        shinfo = New SHFILEINFO
        Dim openFileDialog1 As OpenFileDialog
        openFileDialog1 = New OpenFileDialog

        openFileDialog1.InitialDirectory = "c:\temp\"
        openFileDialog1.Filter = "All files (*.*)|*.*"
        openFileDialog1.FilterIndex = 2
        openFileDialog1.RestoreDirectory = True

        ListView1.SmallImageList = ImageList1
        ListView1.LargeImageList = ImageList1

        shinfo.szDisplayName = New String(Chr(0), 260)
        shinfo.szTypeName = New String(Chr(0), 80)

        If (openFileDialog1.ShowDialog() = DialogResult.OK) Then
            fName = openFileDialog1.FileName

            'Use this to get the small icon.
            hImgSmall = SHGetFileInfo(fName, 0, shinfo, _
                        Marshal.SizeOf(shinfo), _
                        SHGFI_ICON Or SHGFI_SMALLICON)

            'Use this to get the large icon.
            'hImgLarge = SHGetFileInfo(fName, 0,
            'ref shinfo, (uint)Marshal.SizeOf(shinfo),
            'SHGFI_ICON | SHGFI_LARGEICON);

            'The icon is returned in the hIcon member of the
            'shinfo struct.
            Dim myIcon As System.Drawing.Icon
            myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon)

            ImageList1.Images.Add(myIcon)       'Add icon to
            'imageList.

            ListView1.Items.Add(fName, nIndex)  'Add file name and
            'icon to listview.
            nIndex = nIndex + 1
        End If


    End Sub
End Class
0
 
sherrick123Author Commented:

I don't need the Icons.  I want the image that is displayed for a file when you select the "thumbnail" view from the windows explorer.  If there was more documents on how to use the IExtractImage function this would help.
0
 
armoghanCommented:
This has C# code in the last section. It may help
http://www.codetoad.com/asp.net_thumbnails.asp
0
 
Bob LearnedCommented:
And, there's another guru.  Wow, they just keep comin' and comin' :))
0
 
armoghanCommented:
the main guru TheLearnedOne is silent and watching :)
0
 
iboutchkineCommented:
He is waiting untill the rest will be exhausted. Then he as usual will come up with his brilliant ideas :)
0
 
Bob LearnedCommented:
"A man's gotta know his limitations".  Watching and learning :)

Bob
0
 
iboutchkineCommented:
Only sky is the limit!!!!!!!
0
 
armoghanCommented:
come on iboutchkine :) This is all literal things.. There are no limits to human wisdom/knowledge :)
0
 
Bob LearnedCommented:
Thanks guys for sharing your thoughts and your knowledge BTW =:)

Bob
0
 
sherrick123Author Commented:
Well their were some good examples on extracting a thumbnail image BUT since that is not what I was needing help on I would say this problem is unsolvable.  I wanted to see and VB .Net example on using IExtractImage to get ANY file Thumbnail view such as windows XP show in the Folder->View option.
Yes there was some c++ examples but since I don't know c++ that was of no use.

Thanks for everyones help.  This must be one tough problem.
0
 
armoghanCommented:
This was an VB.NET example
http://www.vbaccelerator.com/home/NET/Code/Libraries/Shell_Projects/Thumbnail_Extraction/article.asp

and about the C++ example. Just use its DLL in your VB.NET application
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now