将缩略图转换为用于MS Access的blob

时间:2012-03-26 02:21:00

标签: c# bitmap blob thumbnails

我已将.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();
  }
}

1 个答案:

答案 0 :(得分:0)

尝试替换它:

com.Parameters.AddWithValue("?", pThumbnail);

有了这个:

using (var ms = new MemoryStream())
{
    pThumbnail.Save(ms, pThumbnail.RawFormat);

    com.Parameters.AddWithValue("?", ms.ToArray())
}