-
Sep 29th, 2021, 03:16 AM
#1
Thread Starter
Fanatic Member
Get Audio Type: Get Image Type
Here are a couple of routines for finding the Audio and Image type. I don't claim they are exhaustive as they were written for my needs. I hope someone finds them useful.
Code:
Private Function GetAudioType(sFileName As String) As String
Dim FF As Integer, s As String
s = Space$(420)
FF = FreeFile
Open sFileName For Binary As FF
Get #FF, 1, s
Close FF
Select Case True
Case Mid$(s, 413, 4) = "alac": GetAudioType = "Alac" 'This must come before 'aac'
Case Left$(s, 4) = "ÿñP€", InStr(17, s, "mp4"): GetAudioType = "aac"
Case Mid$(s, 9, 4) = "AIFF": GetAudioType = "Aiff"
Case Left$(s, 4) = "fLaC": GetAudioType = "Flac"
Case Left$(s, 3) = "MAC": GetAudioType = "Monkey"
Case Left$(s, 2) = "ÿû", Left$(s, 3) = "ID3": GetAudioType = "mp3"
Case Left$(s, 3) = "MPC": GetAudioType = "Musepack"
Case InStr(1, s, "OPUS", 1): GetAudioType = "Opus"
Case InStr(1, s, "VORBIS", 1): GetAudioType = "Vorbis"
Case Left$(s, 4) = "RIFF": GetAudioType = "Wav"
Case Left$(s, 4) = "wvpk": GetAudioType = "Wavpack"
Case Left$(s, 7) = "0&²uŽfÏ": GetAudioType = "Wma"
Case Else: GetAudioType = "Unknown"
End Select
End Function
Code:
Private Function GetImageType(sFileName As String) As String
Dim FF As Integer, s As String
s = Space$(12)
FF = FreeFile
Open sFileName For Binary As FF
Get #FF, 1, s
Close FF
Select Case True
Case Left$(s, 4) = Chr$(0) & Chr$(0) & Chr$(1) & Chr$(0): GetImageType = "ICO"
Case Left$(s, 4) = "‰PNG": GetImageType = "PNG"
Case Left$(s, 3) = "ÿØÿ": GetImageType = "JPG"
Case Left$(s, 2) = "BM": GetImageType = "BMP"
Case Left$(s, 3) = "GIF": GetImageType = "GIF"
Case Left$(s, 3) = "II*": GetImageType = "TIFF"
Case Mid$(s, 9, 4) = "WEBP": GetImageType = "WEBP"
Case Mid$(s, 5, 8) = "ftypmif1", Mid$(s, 5, 8) = "ftypheic": GetImageType = "HEIF"
Case Else: GetImageType = "UNKNOWN"
End Select
End Function
Last edited by Steve Grant; Oct 4th, 2021 at 08:00 AM.
Reason: After all this time I just found a jpg using a different signature. Get Image Type updated.
-
Feb 25th, 2022, 07:41 PM
#2
Lively Member
Re: Get Audio Type: Get Image Type
Thanks Steve for the upload. Made a little AVI creator from BMP files from some existing code ages ago. Your code may come in handy for detecting other picture formats (other than Bmp and gif). Thanks again.
I came across an VB6 Exif Reader on GitHub for jpg tiff and png files today that may complement your code. So here it is:
github.com/OlimilO1402/Img_ExifReader
It is 38 Mb in size so best to get it from the GitHub page.
Last edited by CreativeDreamer; Feb 26th, 2022 at 09:10 PM.
-
Feb 26th, 2022, 07:39 AM
#3
Lively Member
Re: Get Audio Type: Get Image Type
Nice work.
For Mp3 Files, if it has and ID3V2 Tag, the first 3 chars are "ID3"
-
Feb 26th, 2022, 04:47 PM
#4
Thread Starter
Fanatic Member
Re: Get Audio Type: Get Image Type
Originally Posted by VBClassic04
Nice work.
For Mp3 Files, if it has and ID3V2 Tag, the first 3 chars are "ID3"
Please read the code more carefully. What happens if there is no V2 tag or no tag at all?
Last edited by Steve Grant; Feb 27th, 2022 at 04:51 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|