|
-
Jul 19th, 2005, 06:59 AM
#1
Jpeg Checker Function
Hi Folks,
I know I haven't yet put in the error checking functions, but apart from that do you see any method to improve this code?
Cheers,
Abhijit
VB Code:
Function CheckForJpegs(ByVal sFile As String) As Boolean
'Author - Abhijit
'Date - 19-July-2005
'Purpose - Check if the given image file is a jpeg file or not.
'Assumption - The image file exists in the given location.
Dim strFileStream As FileStream
Dim binRead As BinaryReader
Dim iByteCounter As Integer
Dim strTemp As String
iByteCounter = 0
strFileStream = New FileStream(sFile, FileMode.Open)
binRead = New BinaryReader(strFileStream)
Dim fileByte() As Byte = binRead.ReadBytes(11)
strFileStream.Close()
For iByteCounter = 0 To 5
strTemp = strTemp & Hex((fileByte(iByteCounter)))
Next iByteCounter
For iByteCounter = 6 To 10
strTemp = strTemp & ChrW((fileByte(iByteCounter)))
Next iByteCounter
If InStr(strTemp, "JFIF", CompareMethod.Text) Then
CheckForJpegs = True
ElseIf strTemp.Substring(0, 5) = "FFD8FF" Then 'This test is required for files created on Mac / older versions on PC
CheckForJpegs = True
Else
CheckForJpegs = False
End If
End Function
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
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
|