vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Erstellen von dynamischen Kontextmen?s - wann immer Sie sie brauchen!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2024
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Fortgeschrittene
Thumbnail von Bild- bzw. Video-Datei erstellen 
Autor: Dikn
Datum: 26.10.16 11:35

Hallo,
ich möchte von Bild- bzw. Video-Datei Thumbnails erstellen. (werden als Bilddateien zur späteren Verwendung im Programm gespeichert)
Das funktioniert mit Bildateien.
Bei Videodateien ist das Thumbnail extrem klein! Wie kann ich das ändern???

Verweis auf 'ThumbnailGenerator.dll'


' PictureBox [pb1]           W/H: 178/101 - BorderStyle = FixedSingle
' ImageList1.Images.Item(0)  W/H: 176/99  - Hintergrund
' ImageList2.Images.Item(0)  W/H:  40/40  - Videosymbol
 
Imports System.IO                        ' File.exists(), Path.GetExtension()
 
Public Class frmMain
  Private Sub Button1_Click(...) Handles Button1.Click
'*****************************************************************************
    Me.pb1.Image = getThumbnail("C:\...\Video.MOV")     ' Bild-W/H: 2816/1584
    'Me.pb1.Image = getThumbnail("C:\...\IMG_1517.JPG")  ' 2816 x 1584 Pixel
    'Me.pb1.Image = getThumbnail("C:\...\Bild1.JPG")     '  772 x  666 Pixel
    'Me.pb1.Image = getThumbnail("C:\...\Bild2.JPG")     '  770 x  260 Pixel
    'Me.pb1.Image = getThumbnail("C:\...\Bild3.JPG")     '  320 x  668 Pixel
  End Sub
 
  Private Function getThumbnail(ByVal strPathFile As String) As Bitmap
'*****************************************************************************
  Dim bolIsVideo As Boolean = False
 
  If File.Exists(strPathFile) Then
    Dim dbRel, dbRelH, dbDelW As Double
    Dim strExt As String = Path.GetExtension(strPathFile).ToLower
    Dim bmFile As Bitmap = Nothing
    Dim bmThumb As New Bitmap(Me.ImageList1.Images.Item(0))
    Dim g As Graphics = Graphics.FromImage(bmThumb)
 
    Select Case strExt
      Case".jpg",".jpeg", ".bmp", ".gif"
        bmFile = DirectCast(Bitmap.FromFile(strPathFile), Bitmap)
 
      Case ".wmv", ".avi", ".mov"
        bolIsVideo = True
        Dim shellIcon As New ShellThumbnail.ShellThumbnail
        bmFile = shellIcon.GetThumbnail(strPathFile)
 
        If bmFile Is Nothing Then bmFile = bmThumb
 
      Case Else
        MsgBox("Datei '" & strPathFile & "' wurde nicht gefunden bzw. ... ", _
                                            MsgBoxStyle.Information, "Fehler")
        Return Nothing
    End Select
 
    Dim W As Integer = bmFile.Width
    Dim H As Integer = bmFile.Height
    dbDelW = W/176
    dbRelH = H/99
 
    If dbDelW > 1 Or dbRelH > 1 Then
      If dbDelW > dbRelH Then
        dbRel = dbDelW
      Else
        dbRel = dbRelH
      End If
      W = CInt(W/dbRel)
      H = CInt(H/dbRel)
    End If
 
    Dim X As Integer = CInt((176-W)/2)
    Dim Y As Integer = CInt((99-H)/2)
 
    g.DrawImage(bmFile, New Rectangle(X,Y,W,H))
 
    If bolIsVideo = True Then
      Dim imgVideo As Image = Me.ImageList2.Images.Item(0)
      Dim recImgVideo As New Rectangle(CInt((176-imgVideo.Width)/2), _
               CInt((99-imgVideo.Height)/2), imgVideo.Width, imgVideo.Height)
      Dim Path As New Drawing2D.GraphicsPath()
      Path.AddEllipse(recImgVideo)
      g.SetClip(Path)
      g.DrawImage(imgVideo, recImgVideo.Left, recImgVideo.Top)
 
      imgVideo.Dispose()
    End If
 
    g.Dispose()
    bmFile.Dispose()
 
    Return bmThumb
 
  Else
    MsgBox("Datei nicht gefunden", MsgBoxStyle.Information, "Fehler")
    Return Nothing
  End If
 
  End Function
End Class
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: Thumbnail von Bild- bzw. Video-Datei erstellen 
Autor: Dikn
Datum: 26.10.16 11:42

zusätzlicher Verweis: ShellThumbnail.dll
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: Thumbnail von Bild- bzw. Video-Datei erstellen 
Autor: Dikn
Datum: 01.11.16 10:44

hab's hinbekommen!
get es vielleicht auch einfacher?

Verweis auf PresentationCore.dll, ThumbnailGenerator.dll, WindowsBase.dll

PictureBox [pb1] W/H: 176/99 - BorderStyle = None
ImageList1.Images.Item(0) W/H: 176/99 - grauer Hintergrund
ImageList1.Images.Item(1) W/H: 176/99 - Videosymbol mit transp. Hintergrund


Imports VistaToolbelt.Shell                          ' ThumbnailGenerator
 
Public Class Form1
 
 
  Private Sub Button1_Click() Handles Button1.Click
'******************************************************************************
    'getThumbnail("C:\...\Video1.avi")               '  720 x  576 
    'getThumbnail("C:\...\Video2.wmv")               ' 1440 x 1080 
    'getThumbnail("C:\...\Video3.mov")               ' 2816 x 1584 
    'getThumbnail("C:\...\Bild1.jpg")                ' 2816 x 1584 
     getThumbnail("C:\...\Bild2.jpg")                '  772 x  666 
    'getThumbnail("C:\...\Bild3.jpg")                '  770 x  260 
    'getThumbnail("C:\...\Bild4.jpg")                '  320 x  668 
    'getThumbnail("C:\...\VideoSymbol.png")          '   40 x   40 
 
    'getThumbnail("C:\...\xxx.png")                  ' -> Exit Sub
  End Sub
 
 
  Private Sub getThumbnail(ByVal strPathFile As String)
'******************************************************************************
  If IO.File.Exists(strPathFile) = False Then
    Beep
    Exit Sub
  End If
 
  Dim imgSource As Windows.Media.ImageSource = _
    ThumbnailGenerator.GenerateThumbnail(strPathFile)
  Dim imgBitmap As Bitmap = ThumbnailGenerator.BitmapSourceToBitmap(imgSource)
  Dim intW As Integer = imgBitmap.Width
  Dim intH As Integer = imgBitmap.Height
  Dim intX As Integer = 0
  Dim intY As Integer = 0
 
  Dim dblRelW, dblRelH As Double
  dblRelW = intW/176: dblRelH = intH/99 
 
  If dblRelW > 1 OR dblRelH > 1 Then
    If dblRelW > dblRelH Then
      intW = CInt(intW/dblRelW): intH = CInt(intH/dblRelW)
    Else
      intW = CInt(intW/dblRelH): intH = CInt(intH/dblRelH)
    End If
  End If
 
  intX = CInt((176-intW)/2): intY = CInt((99-intH)/2)
 
  Dim bmThumb As New Bitmap(ImageList1.Images.Item(0))
  Dim g As Graphics = Graphics.FromImage(bmThumb)
 
  g.DrawImage(imgBitmap, New Rectangle(intX, intY, intW, intH))
 
  Select Case IO.Path.GetExtension(strPathFile).ToLower
    Case ".wmv", ".avi", ".mov"
      Dim imgVideo As Image = ImageList1.Images.Item(1)
      g.DrawImage(imgVideo, 0, 0)
  End Select
 
  pb1.Image = bmThumb
  End Sub
 
End Class
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2024 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel