I have a requirement to verify that a user-specified URL is to an image. So really I need a way to determine that a URL string points to a valid image. How can I do this in .NET?
相关问题
- Views base64 encoded blob in HTML with PHP
- How to get the background from multiple images by
- CV2 Image Error: error: (-215:Assertion failed) !s
- UrlEncodeUnicode and browser navigation errors
- Improve converting string to readable urls
相关文章
- Use savefig in Python with string and iterative in
- Where does this quality loss on Images come from?
- Specifying image dimensions in HTML vs CSS for pag
- How to insert pictures into each individual bar in
- How do I append metadata to an image in Matlab?
- Img url to dataurl using JavaScript
- Click an image, get coordinates
- C# Saving huge images
Here's what I'm using now. Any critiques?
You can't do that without downloading the file (at least a part of it). Use a
WebClient
to fetch the URL and try creating a newBitmap
from the returnedbyte[]
. If it was successful, it's really an image. Otherwise, it will throw an exception somewhere in the process.By the way, you can issue a
HEAD
request and check theContent-Type
header in the response (if it's there). However, this method is not fool-proof. The server can respond with an invalidContent-Type
header.I would use HttpWebRequest to get the headers, then check the content type, and that the content length is non-zero.