如何在C#.net中从数据库中提取图像(使用ms访问) [英] how to reterive the image from database (using ms access) in C# .net

查看:147
本文介绍了如何在C#.net中从数据库中提取图像(使用ms访问)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用内存流时,即出现错误(参数无效)
公共图像byteArrayToImage(byte [] byteArrayIn)
{
MemoryStream ms =新的MemoryStream(byteArrayIn);
//此后出现错误
图片returnImage = Image.FromStream(ms);
return returnImage;
}

While i am using memory stream i had an error namely(parameter is not valid)
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
// i got error hereinafter
Image returnImage = Image.FromStream(ms);
return returnImage;
}

推荐答案

您要检索哪种文件? Image类仅适用于Bitmap(bmp)和Windows Metafile(wmf)文件格式.我的猜测是,您要检索的文件不是这两种类型的文件之一.另一个考虑因素是文件可能已损坏或查询返回空值.
What type of file are you retrieving? The Image class only works for the Bitmap(bmp) and Windows Metafile(wmf) file formats. My guess is the file you are retreiving is not one of these two types of files. Another consideration is the file could be corrupted or the query is returning null.


这实际上非常容易.

在Sql Server中存储图像的图像数据类型实际上是字节流.因此,只需解析它,然后使用相同的mime类型将流存储到文件中即可.

本文可能会为您提供帮助:
http://www.aspfree.com/c/a/ASP.NET/Retrieving-Images-from-a-Database--C---Part-II/


干杯.
:rose:
This is actually very easy.

The image datatype that stores an image in Sql Server is actually a byte stream. So just parse it and store the stream into a file using the same mime type.

This article might help you :
http://www.aspfree.com/c/a/ASP.NET/Retrieving-Images-from-a-Database--C---Part-II/


Cheers.
:rose:


这篇关于如何在C#.net中从数据库中提取图像(使用ms访问)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆