Click here to Skip to main content
15,891,002 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
VB
         Dim data As New vsolicitud
         Insert Dim As New Fsolicitud
 
         'Assign the image
         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

VB
      Protected Sub Button4_Click1 (sender As Object, e As EventArgs) Handles Button4.Click
        Const bmpW = 300 'wide canvas New Picture
        Const BMPH = 226 'tall canvas New Picture

        If (FileUpload1.HasFile) Then
 
            lblMensaje.Text = ""
            'Make sure the uploaded file has a format image file extension
            If (CheckFileType (FileUpload1.FileName)) Then
 
                NewWidth Dim As Integer = bmpW
                NewHeight Dim As Integer = BMPH
                'Use the filename uploaded without the'. 'Extension
                UPNAME Dim As String = Mid (FileUpload1.FileName, 1, (InStr (FileUpload1.FileName, ".") - 1))
                Dim filePath As String = "~ / Images /" & UPNAME & ".png"
 
                'Create a new bitmap using the image as a stream uploaded
                'Set the new resolution bitmap 72 pixels per inch

                Dim upBmp As Bitmap = Bitmap.FromStream (FileUpload1.PostedFile.InputStream)
                Dim newBmp As Bitmap = new Bitmap (newWidth, newHeight, Imaging.PixelFormat.Format24bppRgb)
 
                newBmp.SetResolution (72, 72)
 
                'Get the width and height of uploaded image

                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
 
                'Keep the aspect ratio of the image of the same if not 4: 3 and develop positions newX and Newy
                'To ensure the image is always in the center of the vertical and horizontal fabric

                If upWidth> upHeight Then 'Landscape image

                    Reduces = newWidth / upWidth 'calculate the percentage reduction in width and decimal
                    newHeight = Int (* Reduces upHeight) 'reduce the height of the image uploaded by reducing the amount
                    newy = Int ((BMPH - newHeight) / 2) 'the position of the image down in the center of the canvas
                    newX = 0 'will be wide

                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) 'reduce the height of the image uploaded by reducing the amount
                    newX = Int ((bmpW - newWidth) / 2) 'the position of the image in the center across the canvas
                    newy = 0 'image will be full

                ElseIf upWidth = upHeight Then 'Square Photo

                    Reduces = newHeight / upHeight 'calculate the percentage reduction in height and decimal
                    newWidth = Int (* Reduces upWidth) 'reduce the height of the image uploaded by reducing the amount
                    newX = Int ((bmpW - newWidth) / 2) 'the position of the image in the center across the canvas
                    newy = Int ((BMPH - newHeight) / 2) 'the position of the image down in the center of the canvas

                End If
                'Create a new image of the loaded image using the Graphics class
                'Clear the graph and set the background color to white
                'Antialiasing and high quality bicubic use to maintain good image quality
                'Save the new raster graphics using' PNG image format 'and the calculated positioning Canvas

                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)
 
                    'Show the image I uploaded the resized image control
                    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
Posted
Updated 25-Sep-15 4:30am
v2

1 solution

Or...you could just use Image.GetThumbnailImage[^] - the callback just needs to return false as it's not called any longer.
 
Share this answer
 
Comments
djnilo 25-Sep-15 16:20pm    
thank you very much for resonder originalGriff
what I need is how to record an image more in my database Livian
How to lower the weight to the image? to save
this my code to record the image


  Protected Sub btnGrabar_Click (sender As Object, e As EventArgs) Handles btnagregarimagen.Click
        
         Dim data As New vsolicitud
         Insert Dim As New Fsolicitud

         'Assign the image
         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 Using

         End If
     End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900