' Quote from
'Visual Basic 2005 Cookbook Solutions for VB 2005 Programmers
'by Tim Patrick (Author), John Craig (Author)
'# Publisher: O'Reilly Media, Inc. (September 21, 2006)
'# Language: English
'# ISBN-10: 0596101775
'# ISBN-13: 978-0596101770
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Public Class GetJpgInformation
Public Shared Sub Main
Console.WriteLine(ProcessJPEG.GetJpgInformation("yourfile.jpg"))
End Sub
End Class
Public Class ProcessJPEG
Public Shared Function GetJpgInformation(ByVal whichFile As String) As String
Dim bytesPropertyID As Byte()
Dim stringPropertyID As String
Dim loadedImage As System.Drawing.Bitmap
Dim propertyIDs() As Integer
Dim result As New System.Text.StringBuilder
Dim counter As Integer
Dim scanProperty As Integer
loadedImage = New System.Drawing.Bitmap(whichFile)
propertyIDs = loadedImage.PropertyIdList
For Each scanProperty In propertyIDs
bytesPropertyID = loadedImage.GetPropertyItem(scanProperty).Value
stringPropertyID = System.Text.Encoding.ASCII.GetString(bytesPropertyID)
For counter = 0 To 255
If counter < 32 Or counter > 127 Then
If (stringPropertyID.IndexOf(Chr(counter)) _
<> -1) Then
stringPropertyID = Replace(stringPropertyID, _
Chr(counter), "")
End If
End If
Next counter
' ----- Display the property if it's reasonable.
If (stringPropertyID.Length > 0) And _
(stringPropertyID.Length < 70) Then
result.Append(scanProperty.ToString)
result.Append(": ")
result.AppendLine(stringPropertyID)
End If
Next scanProperty
' ----- Display the results.
Return result.ToString
End Function
Public Shared Function GetString( _
ByVal sourceBytes As Byte()) As String
' ----- Convert a byte array to a string, taking into
' account the terminating null character.
Dim result As String
result = System.Text.Encoding.ASCII.GetString(sourceBytes)
If (result.EndsWith(vbNullChar) = True) Then _
result = result.Substring(0, result.Length - 1)
Return result
End Function
End Class