确定blob是否是一个没有加载整个字段的图像? [英] determine if blob is an image without loading entire field?

查看:284
本文介绍了确定blob是否是一个没有加载整个字段的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法只从数据库中的BLOB类型字段中读取几个字节(对于这个问题,DB品牌并不重要),并确定二进制内容是否是一个图像(假设它是一个:JPG,GIF,PNG)?我有一个webapp在数据库中存储文件,如果它是一个图像,我想显示一个缩略图,否则我想显示一个图标...但我没有任何其他地方存储任何MIMETYPE信息blob (它不是我的设计)...并且因为它是一个webapp,图像的加载需要发生在一个单独的调用(getImage.ashx)从写出< img>标签..当我写出标签时,我不想把整个blob读入库,确定它是一个图像,调整它的大小...等等...我想要能够查看前几个字节,知道我是否需要写标签。我不明白图像文件结构/格式足够好知道在头几个字节,我可以读,以告诉它是一个JPG,GIF或PNG。是否有某种标准头。



有意义吗?



如果你想帮我明确(而不是一般回答是否可以做)使用.NET C#和SQL 2005



谢谢!

解决方案

PNG开始:89 50 4E 47 0D 0A 1A 0A
;请参阅 http://www.libpng.org/pub/png /spec/1.2/PNG-Structure.html



GIF以47 49 46 38 37 61(GIF87a)或47 49 46 38 39 61(GIF89a)开头)
;请参阅 http://www.fileformat.info/format/gif/egff.htm



JPEG以FF D8开头FF E0 xx xx 4A 46 49 46 00(EDIT:添加标题的缺失部分; xx xx是标题长度, );请参阅 http://www.obrador.com/essentialjpeg/headerinfo.htm p>

参考资料: http://wangrui.wordpress.com/2007/06/19/file-signatures-table/


is there a way to read only a few bytes out of a BLOB type field in a database (for this question it doesn't matter the DB brand) and determine if the binary content is an image (assume it is one of: JPG, GIF, PNG)? I have a webapp that stores files in the database, and if it is an image, I want to show a thumbnail, otherwise I want to show an icon... but I don't have any MIMETYPE info stored anywhere else for the blob (it's not my design)... and because it is a webapp, the loading of the image needs to occur in a separate call (getImage.ashx) from writing out the <img> tag.. and when I'm writing out the tag I don't want to have to read the entire blob into a library, determine if it is an image, resize it... etc etc ... I'd like to be able to look at the first few bytes and know whether I need to write the tag or not. I don't understand image file structures/formats well enough to know if there is some sort of standard header in the first few bytes that I could read in to tell if it is a JPG, GIF, or PNG.

make sense?

if you want to help me specifically (instead of generally answering whether it can be done) then I'm using .NET C# and SQL 2005

Thanks!

解决方案

PNGs start with: 89 50 4E 47 0D 0A 1A 0A ; see http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html

GIFs start with 47 49 46 38 37 61 (GIF87a) or 47 49 46 38 39 61 (GIF89a) ; see http://www.fileformat.info/format/gif/egff.htm

JPEGs start with FF D8 FF E0 xx xx 4A 46 49 46 00 (EDIT: adding missing portion of the header; xx xx is the header length, in bytes) ; see http://www.obrador.com/essentialjpeg/headerinfo.htm

reference: http://wangrui.wordpress.com/2007/06/19/file-signatures-table/

这篇关于确定blob是否是一个没有加载整个字段的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆