确定BLOB是没有加载整个领域的形象? [英] determine if blob is an image without loading entire field?

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

问题描述

有没有办法在一个数据库只读的几个字节出一个BLOB类型的字段(对于这个问题,没关系的DB品牌),并确定如果二进制内容是图像(假设它是一个:JPG,GIF,PNG)?我有一个Web应用程序存储在数据库中的文件,如果它是一个形象,我想显示缩略图,否则我要显示一个图标...但我没有保存在其他地方的斑点任何MIMETYPE信息(这不是我的设计)......因为它是一个Web应用程序,图像的加载需要从写出的&lt发生在一个单独的调用(getImage.ashx); IMG>标签..当我写出来的标签,我不希望有读取整个BLOB到库,确定它是否是一个图像,调整其大小......等等等等......我想可以看看前几个字节,并且知道我是否需要写在标签或没有。我不明白的图像文件的结构/格式不够好,知道是否有某种形式的前几个字节标准头的,我可以读说,如果它是一个JPG,GIF或PNG。

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.

有意义吗?

如果你想帮助我明确(而不是通常回答是否是可以做到的),然后我使用.NET C#和SQL 2005

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

谢谢!

推荐答案

PNG格式开始:89 50 4E 47 0D 0A 1A 0A ;看到 http://www.libpng.org/pub/png/规格/ 1.2 / PNG-Structure.html

PNGs start with: 89 50 4E 47 0D 0A 1A 0A ; see 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

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

JPEG图片与FF D8 FF E0 xx月xx 4A开始46 49 46 00(编辑:添加标题的缺失部分; xx月xx是标题的长度,以字节为单位);看到 http://www.obrador.com/essentialjpeg/headerinfo.htm

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

参考: HTTP://wangrui.word press.com / 2007/06/19 /文件签名表/

这篇关于确定BLOB是没有加载整个领域的形象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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