本文介紹了如何將 DataGridView 中的圖像顯示到 PictureBox?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我正在嘗試在我的 DataGridView 中的 PictureBox 中顯示圖像.
我使用 SQL Server 作為數據庫.
I'm trying to show an image in my DataGridView in a PictureBox.
I'm using SQL Server as database.
Me.PictureBox2.Image = DataGridView2.Item(10, i).Value
我想知道我使用的是什么代碼.
I'm wondering what code I am using.
這是錯誤說:
Unable to cast object of type 'System.Byte[]' to type 'System.Drawing.Image'.
推薦答案
您需要將 Blob 字段 Byte 數組(現在是 DataGridView
單元格值)轉換為 Image
對象.
You need to convert the Blob field Byte array (now a DataGridView
cell Value) to an Image
object.
一個 MemoryStream 可用于收集Byte 數組并成為 Stream 源"nofollow noreferrer">Image.FromStream() 方法.
A MemoryStream can be used to collect the Byte array and become the Stream
source for the Image.FromStream() method.
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
這篇關于如何將 DataGridView 中的圖像顯示到 PictureBox?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!