保存并检索图像C# [英] Save and retrieve image C#
问题描述
我有app,但有一些简单的解决方案。
使用此代码插入sql并正常工作。
但是我当把所有工人的照片放在里面时,有2000名员工并且数据库的问题太大
我需要一些帮助或解决方案,以节省一些文件名exmp的情况。 c:\ some folder \ imageofemployee.jpg
点击datagrid行(选择更改)以显示该位置的图片
没有放在sql映像中,只是放在文件位置。
我尝试了什么:
I have app, but have some simple solution.
Using this code to insert into sql and working fine.
But i have 2000 employes and have problem with database was too big when put inside pictures of all workers
I need some help or solution, to save some loaction with file name exmp. c:\some folder\imageofemployee.jpg
When click on datagrid row (selection changed) to show picture from that location
Not put in sql image, just file location.
What I have tried:
//Insert into sql
byte[] img_arr = null;
MemoryStream ms = new MemoryStream();
//dataPictureBox.Image.Save(ms, dataPictureBox.Image.RawFormat);
bool isNullOrEmpty = pictureBox1 == null || pictureBox1.Image == null;
if (!isNullOrEmpty)
pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
img_arr = ms.GetBuffer();
using (SqlConnection openCon = new SqlConnection(cs))
{
string saveStaff = "declare @maxNo integer = 0 select @maxNo = isnull(max(redni_broj), 0) from [dbo].[radnici]; Set @maxNo=@maxNo+1; INSERT INTO dbo.radnici (redni_broj, data) VALUES (@maxNo,@data)";
using (SqlCommand querySaveStaff = new SqlCommand(saveStaff))
{
querySaveStaff.Connection = openCon;
querySaveStaff.Parameters.AddWithValue("@data", img_arr);
openCon.Open();
querySaveStaff.ExecuteNonQuery();
openCon.Close();
}
推荐答案
尝试:
Try:
pictureBox1.Image.Save(@"D:\Temp\MyPic.jpg", ImageFormat.Jpeg);
Image.Save Method(System.Drawing)| Microsoft Docs [ ^ ]
这篇关于保存并检索图像C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!