|
-
Jan 12th, 2010, 08:50 PM
#1
[RESOLVED] Detecting Invalid Images?
Ok, I have a program that parses INI files (yes yes, I know, but I'm stuck with using them, not my own request), and it downloads external images (if the INI contains the path) to the program and cache's them.
Recently, I've run into a snag with the system. Most of the images use Imageshack for storage, but one of them has suddenly 404'd, and whenever I set it to the picturebox to the downloaded image, I get an out of memory error rather quickly (and the file itself is 1kb).
I guess I need to implement a checking system offline to find out if the image is actually an image or just a '404' text...but is there a way to not have to implement this clientside, and have it be checked when I download it?
Here's the downloading code:
vb.net Code:
Public Function DownloadImageStream(ByVal ImageURL As String) As MemoryStream
Dim objImage As MemoryStream 'Create a MemoryStream
Dim objwebClient As WebClient 'Create a WebClient
Dim sURL As String = Trim(ImageURL) 'Remove any leading/ending spaces
Try
'Add the http:// if needed
If Not sURL.ToLower().StartsWith("http://") Then sURL = "http://" & sURL
'Initiate the new WebClient
objwebClient = New WebClient()
Dim url As Uri
url = New Uri(sURL)
'New MemoryStream from downloading the image
'from the specified url
objImage = New MemoryStream(objwebClient.DownloadData(url))
'Return the Image from the downloaded Stream
Return objImage
Catch ex As Exception
'custom error handling, don't worry about this.
Dim err As New default_ErrorDialog
err.ThrowError(ex.Message, ex.StackTrace, ex.InnerException.ToString)
Return Nothing
End Try
End Function
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
|