[求助]读取Access图片

ECYCE 2012-10-14 05:33:58
客户导出了个access, 打开来看到了某列类型是OLE 对象, 数据表里看到的是"图片"
我自己insert了个图片进去, 表里看到的是"长二进制数据"
用oledb读取"长二进制数据"时, 是可以成功的
但用oledb读取"图片"时, Image.FromStream(memoryStream, true);出现Parameter is not valid.
...全文
124 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ECYCE 2012-10-15
  • 打赏
  • 举报
回复
原来它是dib格式, 那又是哪个block呢
ECYCE 2012-10-14
  • 打赏
  • 举报
回复
2楼的我有试了, 对手动插入的有效, 对我那个没效,
根据它的理论, 我也试了for 1 到 60000的都尝试转成image, 全都不行
真不知道怎么导出的
孟子E章 2012-10-14
  • 打赏
  • 举报
回复
你需要使用这个函数转换一下

private byte[] GetImageBytesFromOLEField(byte[] oleFieldBytes)
{
const string BITMAP_ID_BLOCK = "BM";
const string JPG_ID_BLOCK = "\u00FF\u00D8\u00FF";
const string PNG_ID_BLOCK = "\u0089PNG\r\n\u001a\n";
const string GIF_ID_BLOCK = "GIF8";
const string TIFF_ID_BLOCK = "II*\u0000";


byte[] imageBytes;


// Get a UTF7 Encoded string version
Encoding u8 = Encoding.UTF7;
string strTemp = u8.GetString(oleFieldBytes);


// Get the first 300 characters from the string
string strVTemp = strTemp.Substring(0, 300);


// Search for the block
int iPos = -1;
if (strVTemp.IndexOf(BITMAP_ID_BLOCK) != -1)
iPos = strVTemp.IndexOf(BITMAP_ID_BLOCK);
else if (strVTemp.IndexOf(JPG_ID_BLOCK) != -1)
iPos = strVTemp.IndexOf(JPG_ID_BLOCK);
else if (strVTemp.IndexOf(PNG_ID_BLOCK) != -1)
iPos = strVTemp.IndexOf(PNG_ID_BLOCK);
else if (strVTemp.IndexOf(GIF_ID_BLOCK) != -1)
iPos = strVTemp.IndexOf(GIF_ID_BLOCK);
else if (strVTemp.IndexOf(TIFF_ID_BLOCK) != -1)
iPos = strVTemp.IndexOf(TIFF_ID_BLOCK);
else
throw new Exception("Unable to determine header size for the OLE Object");


// From the position above get the new image
if (iPos == -1)
throw new Exception("Unable to determine header size for the OLE Object");


//Array.Copy(
imageBytes = new byte[oleFieldBytes.LongLength - iPos];
MemoryStream ms = new MemoryStream();
ms.Write(oleFieldBytes, iPos, oleFieldBytes.Length - iPos);
imageBytes = ms.ToArray();
ms.Close();
ms.Dispose();
return imageBytes;
}


原文
http://blogs.msdn.com/b/pranab/archive/2008/07/15/removing-ole-header-from-images-stored-in-ms-access-db-as-ole-object.aspx
sirone 2012-10-14
  • 打赏
  • 举报
回复
你把memoryStream读到字节数组,再作为参数试试!

109,897

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧