Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello guys can you please help, how to resize large image to put on picturebox1 so that if the image was already resize, it easy to insert into database

What I have tried:

Dim OFD As New OpenFileDialog

      OFD.Filter = "Jpeg Images *.jpg|*.jpg|Bitmap Images *.bmp|*.bmp|PNG Images *.PNG|*.PNG"

      If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then

          PictureBox1.Image = Image.FromFile(OFD.FileName)

          Dim Newpic As New Bitmap(PictureBox1.Width, PictureBox1.Height)

          Dim g As Graphics = Graphics.FromImage(Newpic)

          g.DrawImage(PictureBox1.Image, 0, 0, PictureBox1.Width, PictureBox1.Height)



      End If
Posted
Updated 18-Dec-19 22:53pm
v2

1 solution

this is my save function

Private Sub SAVECATEGORY_Click(sender As Object, e As EventArgs) Handles SAVECATEGORY.Click

      Dim arrImage() As Byte

      Dim mstream As New System.IO.MemoryStream()
      Dim FileSize As UInt32
      FileSize = mstream.Length
      'CLOSES THE CURRENT STREAM AND RELEASE ANY RESOURCES ASSOCIATED WITH THE CURRENT STREAM

      '  Dim ms As New MemoryStream  '...........need to Imports System.IO from general

      ' PictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
      ' PictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif)
      PictureBox1.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Png) ' ........save IMAGE
      'RETURNS THE ARRAY OF UNSIGNED BYTES FROM WHICH THIS STREAM WAS CREATED
      arrImage = mstream.GetBuffer()
      mstream.Close()

      If PictureBox1.Image Is Nothing Then
          MessageBox.Show("Please Insert image ")
          addcategoryclear()           'you call ddcategoryclear()  to clear textbox and picturebox
      ElseIf TextBox1.Text = "" Then
          MessageBox.Show("Please Insert Image Name")
          addcategoryclear()           'you call ddcategoryclear()  to clear textbox and picturebox
      Else
          '..............
          '..............
          cn.Open()
          Dim command As New MySqlCommand("INSERT INTO `category`( `IMG`, `NAME`) VALUES (@IMG,@NAME)", cn)

          With command.Parameters
              .AddWithValue("@IMG", arrImage)
              '  .Add("@IMG", MySqlDbType.Blob).Value = mstream.ToArray()
              .AddWithValue("NAME", TextBox1.Text)
          End With

          If command.ExecuteNonQuery() = 1 Then

              MessageBox.Show("You Successfully Save")

              addcategoryclear() 'you call ddcategoryclear()  to clear textbox and picturebox
              loadcategory()
          Else
              MessageBox.Show("Something Wrong Pleas Try again")
          End If
          cn.Close()
      End If
      Me.Refresh()
  End Sub
 
Share this answer
 
Comments
Richard Deeming 19-Dec-19 9:14am    
Is this supposed to be the answer to your question?
Member 13910887 20-Dec-19 5:17am    
no!.... when i try to open file dialog and put image to picturebox1 and save it, its save to database thats because the images is 15kb,38kb,98,kb,233 but when it try to save image that 250kb up or 570kb it not save send me error(MySql.Data.MySqlClient.MySqlException: 'Packets larger than max_allowed_packet are not allowed.') , i dont know what to do about that. can you help me Thank you

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