如何从sql server中放入图像的源代码。 [英] How to put source code of image from sql server.

查看:72
本文介绍了如何从sql server中放入图像的源代码。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库,我将图像的路径存储为varchar。现在在我的页面中我想将图像的路径放在Image源中。

解决方案

这个问题的答案可能相当复杂,因为它取决于你的图像在哪里存储库坐着。如果图像在您的网站范围内,那么在数据库中存储图像的相对路径也是明智的,只需在标签中呈现该相对路径



 <   img     src   =  /相对/ DbPath.jpg    /  >  





如果您的图片超出了您网站的范围,您需要确保图片所在的文件夹,是可读的IIS。然后,您可以将图像作为二进制文件打开并传递完成。这也取决于你拥有的ASP网站的类型,如果你使用MVC它更容易,否则你可能想要在你的项目中添加一个ashx文件来处理图像处理。



您的图片看起来像

 <   img     src   =  / Image.ashx?databaseId = 2    /  >  





image.ashx必须打开实际文件(获取数据库中的路径并使用流打开文件,然后将流传递给响应对象。确保将响应类型设置为您要传递的图像类型。

Eduard


I have a database in which I am storing path of the image as varchar. Now in my page I want to put the path of the image in Image source.

解决方案

Answer to this question can be pretty complicated, because it depends on where your images repository sits. If the images are within the scope of your website it's wise to store a relative path to the image in your database as well and just render that relative path in a tag

<img src="/Relative/DbPath.jpg" />



If your images are outside the scope of your website, you need to make sure that the folder the images are in, is readable to IIS. You can then open the image as a binary file and pass is through. This also depends on the type of ASP website you have, if you're using MVC it's even more easy, else you may want to add an ashx file to your project hand handle the image processing from there.

Your images will look like

<img src="/Image.ashx?databaseId=2" />



image.ashx must then open the actual file (fetch the path from the database and open the file with a stream and then pass the stream to the response object. Make sure you set the response type to the type of image you're about to pass.
Eduard


这篇关于如何从sql server中放入图像的源代码。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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