简体   繁体   中英

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

Here I would like to ask, how to display the image data into DevExpress DevExpress gridview or CardView. For I will take a picture of data from mysql database that I keep with BLOB data type.

how or its code if using visual basic.?

for Code that I use:

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

To Screnshoot my program and the results of calling the data from the database, Please Check The Attachment. already I attach the following word file.

ScreenShoot_Program

Please Help and Give The Solution.

Regards,

Tafary

Try This Code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM