2
A
回答
1
可以使用GetInputStream
方法加载图像:
using (var stream = _customer.Photo.GetInputStream()
{
pictureBox1.Image = Image.FromStream(stream);
}
0
使用来自ImageConverter级扩展的方法保存和图像值的负荷可以很容易,即:
pictureBoxLogo.Image.saveImage(obj.Photo);
pictureBoxLogo.Image = ((Image)null).loadImage(obj, obj.Photo);
这里如何Converter-Class可能如下所示:
...
using System.IO;
using CodeFluent.Runtime.BinaryServices;
public static class ImageConverter
{
public static byte[] toByteArray(this Image image)
{
using (var ms = new System.IO.MemoryStream())
{
image.Save(ms, image.RawFormat);
return ms.ToArray();
}
}
public static Image toImage(this byte[] bytesArr)
{
MemoryStream memstr = new MemoryStream(bytesArr);
Image img = Image.FromStream(memstr);
return img;
}
public static Image loadImage(object entity, BinaryLargeObject image)
{
if (entity != null && image != null)
{
using (var stream = image.GetInputStream())
{
if (stream.Length > 0)
return Image.FromStream(stream);
else
return null;
}
}
else
return null;
}
public static Image loadImage(this Image owner, object entity, BinaryLargeObject image)
{
return loadImage(entity, image);
}
public static void saveImage(this Image owner, BinaryLargeObject image)
{
if (owner != null && image != null)
image.Save(owner.toByteArray());
}
}
相关问题
- 1. Nhibernate与Windows窗体
- 2. WPF与Windows窗体 - STAThread
- 3. WPF DataGrid与Windows窗体DataGridView
- 4. Windows窗体设计与ListBoxes
- 5. 转换Windows窗体到Windows Metro窗体
- 6. Windows窗体 - 从父窗体
- 7. BufferedImage imageType in swing
- 8. Windows窗体“洞”
- 9. Windows窗体:PropertyGrid
- 10. 在Windows窗体
- 11. Windows窗体DialogResult
- 12. c#windows窗体
- 13. MVC Windows窗体
- 14. Windows窗体C#
- 15. 什么是AMI ImageType?
- 16. 与Windows窗体的C#类耦合
- 17. Windows窗体与字符串表
- 18. Windows窗体的CheckBox CheckedChanged与CheckStateChanged对比
- 19. Intermitant DefinitionInvalidException与Windows窗体ReportViewer 2008
- 20. 用户控件与Windows窗体
- 21. ASP.NET窗体身份验证与Windows Safari
- 22. AccessViolationException与Windows窗体中的浏览器
- 23. 与Windows Awesomebar类似的行为窗体
- 24. Windows窗体Gridview与asp.net gridview不同?
- 25. 从Windows窗体切换到Web窗体
- 26. Windows窗体,窗体的图标问题
- 27. 窗体的透明背景(Windows窗体)
- 28. Windows窗体中的主窗体
- 29. CodeFluent vs Interop.MSScriptControl.dll
- 30. Windows窗体TextBox Bug?
感谢您的示例! –