
07/08/2007, 09:12
|
 | | | Fecha de Ingreso: febrero-2007
Mensajes: 103
Antigüedad: 18 años Puntos: 1 | |
Re: cargar imagen a una bd Hola Traviz
Pues antes de guardar una imagen tienes que convertirla al tipo byte(), te pongo las funciones para que puedas convertir y guardar la imagen de un picturebox y que puedas convertir y mostrar la imagen en un picturebox:
Public Shared Function Image2Bytes(ByVal img As System.Drawing.Image) As Byte()
Dim sTemp As String = System.IO.Path.GetTempFileName()
Dim fs As New System.IO.FileStream(sTemp, IO.FileMode.OpenOrCreate, IO.FileAccess.ReadWrite)
img.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg)
fs.Position = 0
'
Dim imgLength As Integer = CInt(fs.Length)
Dim bytes(0 To imgLength - 1) As Byte
fs.Read(bytes, 0, imgLength)
fs.Close()
Return bytes
End Function
Public Shared Function Bytes2Image(ByVal bytes() As Byte) As System.Drawing.Image
If bytes Is Nothing Then Return Nothing
'
Dim ms As New System.IO.MemoryStream(bytes)
Dim bm As System.Drawing.Bitmap = Nothing
Try
bm = New System.Drawing.Bitmap(ms)
Catch ex As Exception
System.Diagnostics.Debug.WriteLine(ex.Message)
End Try
Return bm
End Function
Saludos |