簡體   English   中英

如何從Mysql將圖像顯示到Devexpress GridView / Devexpress卡視圖中

[英]How To Display Image Into Devexpress GridView / Devexpress Card View From Mysql

在這里,我想問一下如何將圖像數據顯示到DevExpress DevExpress gridview或CardView中。 因為我將使用BLOB數據類型對mysql數據庫中的數據進行拍照。

如果使用Visual Basic怎么辦?

對於我使用的代碼:

Dim Query As String = "SELECT FTO.ALM_NIM as FOTO_ID, FTO.ALM_FOTO as FOTO FROM tbl_foto_alumni as FTO"

Using DA As New MySql.Data.MySqlClient.MySqlDataAdapter(Query, MyKonection)
   Dim DTwisda As New DataTable
   DA.Fill(DTwisda)
   if Dtwisda.Rows.Count > 0 Then
      GridControl.Datasource = DTwisda
      MainView = CardView1
      Dim RepItemImg As New Repository.RepositoryItemPictureEdit()
      RepItemImg.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Stretch
      RepItemImg.BestFitWidth = 100
      RepItemImg.CustomHeight = 150
      With CardView1.Columns("FOTO")
           .ColumnEdit = RepItemImg
      End With
      With CardView1
           .OptionsBehavior.FieldAutoHeight = True
           .MaximumCardRows = 2
           .MaximumCardColumns = 6
      End With
   End If
End Using

要檢查我的程序以及從數據庫中調用數據的結果,請檢查附件。 我已經附加了以下word文件。

ScreenShoot_Program

請幫助並給出解決方案。

問候,

塔法里

嘗試以下代碼:

Dim row As DataRow
            Dim i As Integer
            For Each row In myDt.Rows
                Column = New DataColumn
                With Column
                    .DataType = GetType(Bitmap)
                    ' .DefaultValue = Base64ToImage(row("Photo"))
                    .Unique = False
                    .ColumnName = "EmpPhoto"
                End With
                If Not myDt.Columns.Contains("EmpPhoto") Then
                    myDt.Columns.Add(Column)
                End If
                myDt.Rows(i)("EmpPhoto") = Base64ToImage(row("Photo"))
                i += 1
                myDt.AcceptChanges()
            Next
            i = 0
            'myDt.Rows.Add(Column.DefaultValue)

 Public Function Base64ToImage(base64String As String) As Image
    Try
        ' Convert Base64 String to byte[]
        Dim imageBytes As Byte() = Convert.FromBase64String(base64String)
        Dim ms As New MemoryStream(imageBytes, 0, imageBytes.Length)
        ' Convert byte[] to Image
        ms.Write(imageBytes, 0, imageBytes.Length)
        Dim image1 As Image = Image.FromStream(ms, True)
        Return image1
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Function

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM