.NET位图对象 [英] .NET Bitmap Object

查看:136
本文介绍了.NET位图对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将图像存储为数据库中的BLOB(Varbinary(max))。我将图像编码为.NET Bitmap TIFF。在页面上显示图像时,我可以将内容类型设置为JPEG,GIF等,并且图像始终在网页上正确显示。如果我将内容类型设置为TIFF(因为它被编码为TIF),我希望图像只能正确显示。我正在使用Bitmap类。我错过了什么吗?



以下是一些代码:

  objCmd.CommandText =SELECT Img FROM dbImage,其中id = 1 
dr = objCmd.ExecuteReader
dr.Read()

screenshot = CType(dr(screenshot),Byte())
Response.ContentType =image / tiff
Response.BinaryWrite(screenshot)
Response.Flush()
Response.End()

BLOB图像被编码为TIFF。但是,当提取图像时,它将以JPG和GIF显示。例如,如果我更改了response.contenttype到image / jpg,然后它仍然显示。问题是:为什么它仍然显示?我没有很多图像处理经验。

解决方案

它仍然显示的原因是因为现代浏览器忽略图像的内容类型标题(基于观察和测试,而不是文档)。几乎所有图像的前几个字节都会告诉你它的格式是什么 - 我假设浏览器(以及它们使用的图形库)看起来像这些字节(就像.NET一样),而不是依赖于内容类型的标题。 / p>

网络服务器没有重新编码图像


I have stored an image as a BLOB (Varbinary(max)) in a database. I encoded the image as a .NET Bitmap TIFF. When displaying the image on the page, I am able to set the content type as JPEG, GIF etc and the image always appears correctly on the web page. I would expect the image only to appear correctly if I set the content type as TIFF (as it was encoded as TIF). I am using the Bitmap class. Am I missing something?

Here is some code:

objCmd.CommandText = "SELECT Img FROM dbImage where id = 1
                dr = objCmd.ExecuteReader
                dr.Read()

                screenshot = CType(dr("screenshot"), Byte())
                Response.ContentType = "image/tiff"
                Response.BinaryWrite(screenshot)
                Response.Flush()
                Response.End()

The BLOB image was encoded as a TIFF. However, when extracting the image it will display in JPG and GIF. For example, if I changed response.contenttype to "image/jpg", then it still displays. The question is: why does it still display? I don't have a lot of experience with image processing.

解决方案

The reason it still displays is because modern browsers ignore the content-type header for images (based on observation and testing, not on documentation). The first few bytes of nearly every image will tell you what format it is in - I assume browsers (and the graphics libraries they use) look to these bytes (just as .NET does) instead of relying on the content-type header.

The web server is NOT re-encoding the image

这篇关于.NET位图对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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