good afternoon
asp.net vb
mysql
lords programmers can be oriented by fa
I have a entry form gift requests the user must enter a photograph in the FileUpload1 up image
this my code to record the image works
Dim data As New vsolicitud
Insert Dim As New Fsolicitud
Then if FileUpload1.HasFile
Using reader As New BinaryReader (FileUpload1.PostedFile.InputStream)
Dim image As Byte () = reader.ReadBytes (FileUpload1.PostedFile.ContentLength)
datos._nombre = FileUpload1.FileName
datos._length = FileUpload1.PostedFile.ContentLength
datos._numsolicitud = TxtNumSolicitud.Text
datos._imagen = image
insertar.GuardarImagen (data)
end if
then I started searching the internet a code that pirmitira me culquier reduce code size image I found on the internet select any image and put certain size and saves folder that has the site
my problem is that this code is stored in a folder to display the image
as I need to add my code to record the image rise
what I intend to display the image and then record
this code
Protected Sub Button4_Click1 (sender As Object, e As EventArgs) Handles Button4.Click
Const bmpW = 300
Const BMPH = 226
If (FileUpload1.HasFile) Then
lblMensaje.Text = ""
If (CheckFileType (FileUpload1.FileName)) Then
NewWidth Dim As Integer = bmpW
NewHeight Dim As Integer = BMPH
UPNAME Dim As String = Mid (FileUpload1.FileName, 1, (InStr (FileUpload1.FileName, ".") - 1))
Dim filePath As String = "~ / Images /" & UPNAME & ".png"
Dim upBmp As Bitmap = Bitmap.FromStream (FileUpload1.PostedFile.InputStream)
Dim newBmp As Bitmap = new Bitmap (newWidth, newHeight, Imaging.PixelFormat.Format24bppRgb)
newBmp.SetResolution (72, 72)
UpWidth Dim As Integer = upBmp.Width
UpHeight Dim As Integer = upBmp.Height
NewX Dim As Integer = 0
Newy Dim As Integer = 0
As Decimal Dim reduced
If upWidth> upHeight Then
Reduces = newWidth / upWidth
newHeight = Int (* Reduces upHeight)
newy = Int ((BMPH - newHeight) / 2)
newX = 0
UpWidth ElseIf <upheight then="Portrait picture<br mode="hold" /><br mode="hold" /> Reduces = newHeight / upHeight " calculate="" the="" percentage="" reduction="" in="" height="" and="" mode="hold" /> newWidth = Int (* Reduces upWidth)
newX = Int ((bmpW - newWidth) / 2)
newy = 0
ElseIf upWidth = upHeight Then
Reduces = newHeight / upHeight
newWidth = Int (* Reduces upWidth)
newX = Int ((bmpW - newWidth) / 2)
newy = Int ((BMPH - newHeight) / 2)
End If
Dim newGraphic As Graphics = Graphics.FromImage (newBmp)
Try
newGraphic.Clear (Color.White)
newGraphic.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
newGraphic.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
newGraphic.DrawImage (upBmp, newX, newy, newWidth, newHeight)
newBmp.Save (MapPath (filePath) Imaging.ImageFormat.Png)
imgSubida.ImageUrl = filePath
imgSubida.Visible = True
Catch ex As Exception
lblMensaje.Text = ex.ToString
Finally
upBmp.Dispose ()
newBmp.Dispose ()
newGraphic.Dispose ()
End Try
Else
lblMensaje.Text = "Please select an image with an extension format of BMP, JPG, JPEG, GIF or PNG file."
End If
End If
End Sub
CheckFileType Function (ByVal fileName As String) As Boolean
As String Dim ext = Path.GetExtension (filename)
Select Case ext.ToLower ()
Case ".gif"
Return True
Case ".png"
Return True
Case ".jpg"
Return True
Case ".jpeg"
Return True
Case ".bmp"
Return True
Case Else
Return False
End Select
End Function
End Class