Click here to Skip to main content
       

Visual Basic

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHow can i retrieve image to pictureBox ?memberheinhtataung1 Nov '12 - 18:04 
I'm using Stored Procedure,3 tier and VB.net. Smile | :)
Now, i click the gridview and then want to show the data in textboxes and pictureBox to update the informations. Roll eyes | :rolleyes: Java | [Coffee]
The problem is that , how can i retrieve photo to picture box???Confused | :confused: Dead | X| D'Oh! | :doh: Mad | :mad: Cry | :((
 
Here is my code Hmmm | :|
 
  Private Sub gdCompany_CellClick(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles gdCompany.CellClick
        btnSave.Text = "ျပင္ရန္"
        txtCompanyName.Text = gdCompany.CurrentRow.Cells(1).Value.ToString()
        txtDescription.Text = gdCompany.CurrentRow.Cells(2).Value.ToString()
        txtPhoneNo.Text = gdCompany.CurrentRow.Cells(3).Value.ToString()
        txtFaxNo.Text = gdCompany.CurrentRow.Cells(4).Value.ToString()
        txtEmail.Text = gdCompany.CurrentRow.Cells(5).Value.ToString()
        txtWebsite.Text = gdCompany.CurrentRow.Cells(6).Value.ToString()
        ddlBankName.SelectedValue = Convert.ToInt32(gdCompany.CurrentRow.Cells(7).Value.ToString())
        ddlBankBranch.SelectedValue = Convert.ToInt32(gdCompany.CurrentRow.Cells(8).Value.ToString())
        txtBankAccountNo.Text = gdCompany.CurrentRow.Cells(9).Value.ToString()
        txtAddress.Text = gdCompany.CurrentRow.Cells(10).Value.ToString()
 
        'picCompanyLogo.Image = Convert.ToByte(gdCompany.CurrentRow.Cells(15).Value.ToString())
       
 
      
        txtCompanyName.Focus()
    End Sub

AnswerRe: How can i retrieve image to pictureBox ? PinmemberEddy Vluggen2 Nov '12 - 0:57 
I'd recommend creating a "new application" to try implement this technique; that way you won't be bothered with code that has little to do with this particular problem.
 
You already have the bytes; you can put those in a memorystream[^] and load your image from that stream[^].
Bastard Programmer from Hell Suspicious | :suss:
if you can't read my code, try converting it here[^]

AnswerRe: How can i retrieve image to pictureBox ? PinmemberSZLMCL6 Nov '12 - 23:20 
hy
 
This function converts byte array to image:
 
Public Shared Function ByteArrayToImage(ByVal ByteArr() As Byte) As Object
                Dim ImageStream As System.IO.MemoryStream
 
                Try
                    If ByteArr.GetUpperBound(0) > 0 Then
                        ImageStream = New System.IO.MemoryStream(ByteArr)
                        Return Image.FromStream(ImageStream)
                    Else
                        Return Nothing
                    End If
                Catch ex As Exception
                    Return Nothing
                End Try
            End Function
 
and this convert back:
 
 Public Shared Function ImageToByteArray(ByVal NewImage As Image) As Object
                Dim ImageStream As System.IO.MemoryStream
                Dim ByteArr() As Byte
 
                Try
                    ReDim ByteArr(0)
                    If NewImage IsNot Nothing Then
                        ImageStream = New System.IO.MemoryStream
                        NewImage.Save(ImageStream, Imaging.ImageFormat.Jpeg)
                        ReDim ByteArr(CInt(ImageStream.Length - 1))
                        ImageStream.Position = 0
                        ImageStream.Read(ByteArr, 0, CInt(ImageStream.Length))
                    End If
                    Return ByteArr
                Catch ex As Exception
                    Return Nothing
                End Try
            End Function
 
+You need DBNull check when the column allow nulls.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 21 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid