如何在数据库中插入图像 [英] How to insert image in database

查看:88
本文介绍了如何在数据库中插入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何在数据库中插入图像.

我正在使用ASP.NET,C#,SQL2005和Microsoft Visual
Studio2008.



How to insert image in database .

i am using ASP.NET,C#,SQL2005 and Microsoft Visual
Studio 2008.

推荐答案

将图像插入数据库

第一种方法:将图像存储在服务器中,然后将imageurl(存储的图像文件路径)传递给数据库

第二种方法:首先将图像转换为字节格式,然后存储到数据库中(使用表中的blob数据类型).
Inserting Image into database

1st Method: Store image in your server and pass the imageurl(stored image file path) to data base

2nd method :First Convert image into byte format then store into database(use the blob datatype in your table).


您需要传递二进制格式的图像"或文件夹"使用ADO.NET将图像存储到的位置''存储到数据库中!在此处阅读有关ADO.NET的信息,它将对您有所帮助.

看看这些:
MSDN:ADO.NET [ MSDN:使用ADO.NET访问数据 [ ^ ]


如有需要,请参考以下文章:
上传和存储图像数据库和图像到文件夹的路径-第1部分 [上传和存储图像数据库和图像到文件夹的路径-第2部分 [ ^ ]
在C#中从SQL数据库检索图像 [
You need to pass ''image in binary format'' or ''folder location where image is stored'' to your database using ADO.NET! Read about ADO.NET here and it will help you.

Look at these:
MSDN: ADO.NET[^]
MSDN: Accessing Data with ADO.NET[^]


Following articles for reference, if needed:
Uploading and Storing Image Path to Database and Image to Folder - Part 1[^]
Uploading and Storing Image Path to Database and Image to Folder - Part 2[^]
Retrieving Image from SQL Database in C#[^]


 byte[] ImageBytes;
void ImageinBytes()
{
if (!string .IsNullOrEmpty ( FileName)) 
            {
                 Bitmap BitMap1 = new Bitmap(FileName);
                 System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream();
                BitMap1.Save(MemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                ImageBytes = MemoryStream.ToArray();
            }
}




此处FileName是File的完整路径.



用于再次提取图像中的字节




here FileName is complete path of File.



For extracting Bytes in Image again

void CovertingInImage()
        {
            System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream(ImageBytes);
            Bitmap BitMap2 = new Bitmap(MemoryStream);
            Image Image1;
            Image1 = Image.FromStream(MemoryStream);
        }



这里的图片字节数是



Here imagebytes is


这篇关于如何在数据库中插入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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