Monday, June 8, 2020

[VB][Resolved] Get IPTC information from jpg without any external library

Add 2 dll as reference which are both included with the Microsoft .NET Framework:
WindowsBase.dll
PresentationCore.dll

Add this link in front of your class:
Imports System.Windows.Media.Imaging

Function:
Public Function getIPTCCaption(ByVal strSrc As String, By strReturnMsg As String) As Boolean
  Dim blnReturn As Boolean = True
  Try
    Dim stream As Stream = New FileStream(strSrc, FileMode.Open, FileAccess.Read)
    Dim decoder = New JpgeBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.None)
    Dim metaData = decoder.Frame(0).MetaData
    strReturnMsg = metaData.getQuery("/app13/irb/8bimiptc/iptc/Caption").ToString()
  Catch ex As Exception
    strReturn = ""
    blnReturn = False
  End Try
  Return blnReturn
End Function

Reference:

https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.imaging.jpegbitmapdecoder?view=netcore-3.1

No comments :

Post a Comment