Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
*** RUTINA DEL BOTON (CARGO LA IMAGEN DE ALGUN DISCO O ALGO EN EL PICTUREBOX)
Private Sub btnSeleccionarImagen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btnSeleccionarImagen.Click
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.Filter = "Imgenes |*.jpg; *.png; *.gif"
openFileDialog1.Title = "Seleccione una Imagen"
' Show the Dialog.
' If the user clicked OK in the dialog and
' a .CUR file was selected, open it.
If openFileDialog1.ShowDialog() = DialogResult.OK Then
' Assign the cursor in the Stream to the Form's Cursor property.
Me.pbImagen.ImageLocation = openFileDialog1.FileName
Me.pbImagen.Load()
Else
Me.pbImagen.Image = Nothing
End If
End Sub
******* UTILIZO UNA CLASE IMAGEMANIPULATION (mezcla de cosas encontradas en internet con
algunas modificaciones) DONDE SE ACHICA LA IMAGEN Y DONDE LA CONVIERTO A BYTES P/
GUARDAR Y VICEVERSA
Imports System.Drawing.Imaging
Public Class ImageManipulation
Public Shared Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo
Dim j As Integer
Dim encoders As ImageCodecInfo()
encoders = ImageCodecInfo.GetImageEncoders()
For j = 0 To encoders.Length
If encoders(j).MimeType = mimeType Then
Return encoders(j)
End If
Next j
Return Nothing
End Function
Public Shared Sub SaveJPGWithCompressionSetting(ByVal image As Image, ByVal szFileName As String, ByVal lCompression As
Long)
Dim eps As EncoderParameters = New EncoderParameters(1)
eps.Param(0) = New EncoderParameter(Encoder.Quality, lCompression)
Dim ici As ImageCodecInfo = GetEncoderInfo("image/jpeg")
Try
image.Save(szFileName, ici, eps)
Catch exc As Exception
MessageBox.Show(exc, " Atencin !", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
fs.Read(rawData, 0, FileSize)
fs.Close()
Return rawData
End Function
Public Shared Function Bytes2Image(ByVal bytes() As Byte) As Image
If bytes Is Nothing Then Return Nothing
'
Dim ms As New System.IO.MemoryStream(bytes)
Dim bm As Bitmap = Nothing
Try
bm = New Bitmap(ms)
Catch ex As Exception
System.Diagnostics.Debug.WriteLine(ex.Message)
End Try
Return bm
End Function
End Class
'Mysql.myCommand.Parameters.Add("?Image", Me.rawData)
Mysql.myCommand.Parameters.Add("?Image", ImageManipulation.Image2Bytes(pbImagen.Image))
'Mysql.myCommand.Parameters.Add("?Image", Me.rawData)
Mysql.myCommand.ExecuteNonQuery()
Mysql.myCommand.Parameters.Clear()
MessageBox.Show("El Producto se ha guardado con xito", "PRODUCTO GUARDADO!", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
Catch ex As Exception
'Panel.registrarError(ex.Message & "(ProductosAm/GuardaNuevo)")
'Respuesta = "Error al guardar, Reintente - \n" & ex.Message
Mysql.myCommand.CommandText = "rollback"
Mysql.myCommand.ExecuteNonQuery()
MessageBox.Show("", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
Mysql.myCommand.CommandText = "commit"
Mysql.myCommand.ExecuteNonQuery()
End Try
End Sub
Mysql.myReader.Close()
End If
Mysql.myReader.Close()
end sub
******* CON ESTO LOGRO GUARDAR IMGENES DE 300 X 220 INDEPENDIENTEMENTE DEL TAMAO
DE LA IMAGEN DE ORIGEN PARA Q NO SEAN MUY PESADAS, EL TAMAO FINAL SE PUEDE
MODIFICAR EN LA CLASE IMAGEMANIPULATION