将缩略图转换为用于MS Access的blob
本文关键字:MS Access blob 用于 略图 转换 | 更新日期: 2023-09-27 18:28:54
我已经将.jpg图像转换为位图缩略图。我现在要做的是将缩略图转换为MS Access的blob。我最近开始学习计算机编程,所以我的代码可能很草率,但是,我现在的代码是:
foreach (String files in Directory.GetFiles(dig.SelectedPath))
{
if (files.EndsWith(".JPG"))
{
//convert .jpg to thumbnail
Image image = new Bitmap(files);
Image pThumbnail = image.GetThumbnailImage(100, 100, null, new IntPtr());
//need code entered here to convert pThumbnail into a byte to be able to convert
//the thumbnail into blob
//To insert thumbnail into access if I can convert into blob
string cmdstr = "INSERT into IMGSTR(Path, Images) values(?, ?)";
OleDbCommand com = new OleDbCommand(cmdstr, vcon);
com.Parameters.AddWithValue("?", files);
com.Parameters.AddWithValue("?", pThumbnail);
com.ExecuteNonQuery();
image.Dispose();
}
}
尝试替换这个:
com.Parameters.AddWithValue("?", pThumbnail);
有了这个:
using (var ms = new MemoryStream())
{
pThumbnail.Save(ms, pThumbnail.RawFormat);
com.Parameters.AddWithValue("?", ms.ToArray())
}