Hi @Sani Love ,
Here is an optional way to check the file format: Checking the file's magic numbers.
Magic numbers are the first bits of a file which uniquely identify the type of file. This makes programming easier because complicated file structures need not be searched in order to identify the file type.
You can find the magic number in the file format you want by searching.
For example, The magic numbers for JPEG are FF, D8, FF, E0, and PNG are 89, 50, 4E, 47.
Imports System.IO
Public Class ImageDetection
Public Shared Function IsImage(stream As Stream) As Boolean
Dim buffer As Byte() = New Byte(7) {} ' Read 8 bytes to check magic numbers
stream.Read(buffer, 0, 8)
If buffer(0) = &HFF AndAlso buffer(1) = &HD8 AndAlso buffer(2) = &HFF AndAlso buffer(3) = &HE0 Then
Return True
End If
If buffer(0) = &H89 AndAlso buffer(1) = &H50 AndAlso buffer(2) = &H4E AndAlso buffer(3) = &H47 Then
Return True
End If
Return False
End Function
End Class
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.