sql-server - 如何将图像从 DataGridView 显示到 PictureBox?
问题描述
我正在尝试在 PictureBox 中的 DataGridView 中显示图像。
我使用 SQL Server 作为数据库。
Me.PictureBox2.Image = DataGridView2.Item(10, i).Value
我想知道我正在使用什么代码。
这是错误说:
Unable to cast object of type 'System.Byte[]' to type 'System.Drawing.Image'.
解决方案
您需要将 Blob 字段字节数组(现在是DataGridView
单元格值)转换为Image
对象。
MemoryStream可用于收集 Byte 数组并成为Image.FromStream()方法的Stream
来源。
If DataGridView2(10, 1).Value Is Nothing Then Return
Using ms As MemoryStream = New MemoryStream(CType(DataGridView2(10, i).Value, Byte()))
PictureBox2.Image?.Dispose()
PictureBox2.Image = Image.FromStream(ms)
End Using
推荐阅读
- python - 列的最大值和最小值之间的差异
- c# - Android Xamarin 绑定:类构造函数中的枚举
- qt - 如何创建 QSharedPointer
> 带有初始化列表? - spring - 自定义 Spring @Profile 注解
- laravel - 照亮我 - 在此代码的 Lumen 中获取功能
- r - 如何将 tidygraph tibble 的节点和边缘部分分离成两个单独的纯 tibble
- sharepoint - 需要材料在线学习 Sharepoint
- reactjs - 开玩笑地使用 Google 登录测试 Firebase 身份验证
- c# - Azure Devops Pipeline 构建器无法在引用的 dll 中看到命名空间
- python - 浮点格式在 Python 中转换为年月格式