我怎么检索使用C#从数据库中多张图片 [英] how do I retrieve multiple images from the database using c#

查看:319
本文介绍了我怎么检索使用C#从数据库中多张图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有9图像,这不断变化的数据库,所以我不能直接设置的src 在HTML < IMG> 标签来显示9张图像,我不得不从数据库中接他们,并相应地约束他们。

I have a database of 9 images, which keep changing, so I cannot directly set the src in html <img> tag to display the 9 images, I have to pick them from the database and bind them accordingly.

我能够检索和使用打印1张图像 Response.BinaryWrite(),但不是所有的9.我的字节[] 从数据库中只获得第1图像,

I'm able to retrieve and print 1 image using Response.BinaryWrite(), but not all 9. My byte[] gets only the 1st image from the db,

这里的code,

            while (dr.Read())
            {
                Response.ContentType = "image/jpg";
                Response.BinaryWrite((byte[])(dr["fsImage"]));

            }

我如何检索所有9张图像,以及我如何将它们绑定为&LT; ASP:图像&GT; 标记或构建一个HTML &LT ; IMG&GT; 标签动态

How do I retrieve all 9 images, and how do I bind them to either <asp:Image> tag or construct an html <img> tag dynamically

我是一个新手,所以请把它容易对我来说,如果有愚蠢的错误;)

I'm a novice, so please take it easy on me, if there are stupid mistakes ;)

在此先感谢。

推荐答案

您不能有网页给所有图像的内容。

You can't have the web page give the content of all the images.

在以动态呈现你需要做一个页面,这将给你一个图像的图像。该页面会使用code像你有什么上面。

In order to "dynamically" render the image you need to make a page which will give you a single image. This page would use code like what you have above.

然后挑来显示的URL页面哪种图片,例如更改

Then to pick which image to show the url to the page would change for example

http://youdomain/makeimage.aspx?imageid=1

http://youdomain/makeimage.aspx?imageid=2

在制作图像的code会再回到单一的形象。

The code in make image would then return the single image.

一个音符 - 你会愉快得多,如果您的网址

A note -- you will be much happier if you make the url

http://youdomain/makeimage.aspx?imageid=1&mytype=.jpg

因此​​具有扩展的图像URL结束。有些浏览器(IE)欺骗和看字符串的结尾,看看有什么内容类型的期望。他们将与上面一样,但不是一个URL工作没有试用.JPG。

Thus having the image url end in the extension. Some browsers (IE) cheat and look at the end of the string to see what content type to expect. They will work with a url like above but not without the trialling .jpg.

此外,你将需要实施某种形式的缓存我们你的表现将是一个狗(ESP如果你试图扩展。)

Also, you will need to implement some form of caching our your performance will be a dog (esp if you try to scale.)

祝你好运。

这篇关于我怎么检索使用C#从数据库中多张图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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