图像在数据库中上传 [英] image uploading in database
本文介绍了图像在数据库中上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在html页面上使用javascript上传图片,并希望将Wcf中的图像转换为存储在数据库中
i want to upload the image using javascript on html page and wants to convert the image in bytes in Wcf to store in database
推荐答案
以下两种帮助方法应该能够做到这一点:
public BitmapImage ImageFromBuffer(Byte [] bytes)
{
MemoryStream stream = new MemoryStream(bytes) ;
BitmapImage image = new BitmapImage();
image.BeginInit();
image.StreamSource = stream;
image.EndInit();
返回图片;
}
public Byte [] BufferFromImage (BitmapImage imageSource)
{
流stream = imageSource.StreamSource;
Byte [] buffer = null;
if(stream!= null && stream.Length> 0)
{
using(BinaryReader br = new BinaryReader(stream))
{
buffer = br.ReadBytes((Int32)stream.Leng th);
}
}
返回缓冲区;
}
我没有完全测试这两种方法,但同样的概念应该是真的。
希望这有助于
The following two helper methods should be able to do the trick:
public BitmapImage ImageFromBuffer(Byte[] bytes)
{
MemoryStream stream = new MemoryStream(bytes);
BitmapImage image = new BitmapImage();
image.BeginInit();
image.StreamSource = stream;
image.EndInit();
return image;
}
public Byte[] BufferFromImage(BitmapImage imageSource)
{
Stream stream = imageSource.StreamSource;
Byte[] buffer = null;
if (stream != null && stream.Length > 0)
{
using (BinaryReader br = new BinaryReader(stream))
{
buffer = br.ReadBytes((Int32)stream.Length);
}
}
return buffer;
}
I don''t fully test the two methods, but the same concept should be true.
Hope this helps
这篇关于图像在数据库中上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文