从mysql数据库插入和检索图像
我必须使用涉及将图片存储在数据库中的应用程序.首先,我将图像存储在文件夹中,并将图片的名称存储在数据库中,这样我就可以通过从数据库中检索图片的名称来获取图片.但是,当图片的位置发生变化时,最近开始出现问题.
因此,我真的需要有关如何从mysql数据库中插入和检索图片的帮助.
我还需要有关要使用的正确数据类型的帮助,无论是blob,verbinary还是其他类型.
如果有人可以帮忙,我将非常感谢.
I have to work with an application that involves storing pictures in the database. At first, i was storing the images in the folder and the names of the pictures in the database so that i can get a picture by retrieving the name of the picture from the database. But problems started to arise recently when the location of the picture got change.
So I really need help in how to insert and retrieve pictures from a mysql database.
I also need help about the correct data type to use, whether blob, verbinary or what.
I will really appreciate it if anyone can help out.
下面的链接可能会对您有所帮助
将图像保存到SQL Server 2000数据库 [ ^ ]
Below link might help you
Save An Image Into SQL Server 2000 Database[^]
您应该更正数据类型,长发".
You should correct data type ,"longblob".
private static byte[] ImageToByteMenthod(Image img)
{
byte[] imageb={};
try
{
MemoryStream imgStream = new MemoryStream();
img.Save(imgStream,ImageFormat.Bmp); //Gif,Jpeg
imageb=imgStream.ToArry();
}
catch
{
//To do
}
return imageb;
}
private static Image ByteToImage(byte[] data)
{
MemoryStream ms = new MemoryStream(data);
Image img = Image.FromStream(ms);
return img;
}
private void Demo()
{
Bitmap bitmap = new Bitmap(this.pictureBox1.Image);
//TO DO
ModelLayer.Product product = new ModelLayer.Product();
//...
product.photo = ImageToByteMenthod(bitmap);
// Insert into DB...
}