Saving picturebox image with graphics in it

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ashiie
    New Member
    • Aug 2013
    • 2

    #1

    Saving picturebox image with graphics in it

    Hi,

    so yeah. what i'm trying to do is load an image from my database create some graphics to it. probably just some lines and marks and save it back to my database. here's so far what I got.
    Code:
    for creating graphics:
    
     }
            private void pictureBox3_MouseDown(object sender, MouseEventArgs e)
            {
                draw = true;
            }
            private void pictureBox3_MouseMove(object sender, MouseEventArgs e)
            {
                if (draw)
                {
                    Graphics g = Graphics.FromImage(pictureBox3.Image);
                    g.FillEllipse(color, e.X, e.Y, 25, 25);
                    pictureBox3.Invalidate();
                }
            }
            private void pictureBox3_MouseUp(object sender, MouseEventArgs e)
            {
                draw = false;
            }
    and for saving it:
    Code:
    }
    private void button15_Click(object sender, EventArgs e)
            {
    
                Image img = pictureBox3.Image;
                byte[] byteImg = ImageToByteArray(img);
                        OleDbConnection oleDbConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Asthred\\Documents\\sad\\Sad.mdb");
                OleDbCommand oleDbCommand = new OleDbCommand();
                oleDbCommand.Connection = oleDbConnection;
                oleDbCommand.CommandText = "UPDATE Patientsinformation SET Toothchart = @image   WHERE Lastname= @tb58 AND Firstname= @tb58 ";
                oleDbCommand.Parameters.AddWithValue("@image", byteImg);
                oleDbCommand.Parameters.AddWithValue("@tb58", tb58.Text);
                oleDbCommand.Parameters.AddWithValue("@tb57", tb57.Text);
                oleDbConnection.Open();
                oleDbCommand.ExecuteNonQuery();
                oleDbConnection.Close();
                MessageBox.Show("Record Updated!");
                this.patientsinformationTableAdapter.Fill(this.sadDataSet.Patientsinformation);
            }
    but the saving part doesnt work :( I think it only saves the image loaded to the picturebox but not the graphics created to it. how to merge it? i've tried to google it and found some sort of same cases but fails to make it work, something like converting it to bitmap. first time c# user by the way so yeah sort of ahh, having a hard time. thanks by the way in advance. help :((
  • bcarey
    New Member
    • Sep 2009
    • 5

    #2
    I am not sure but I think you need to save your Graphics g that was changed and not the original image in the picturebox

    Comment

    • Ashiie
      New Member
      • Aug 2013
      • 2

      #3
      Got it solved :)) thanks anyway.:)
      I finally figured out the converting to bitmap thinggy :D

      converted the image from the picturebox to bitmap

      Code:
      private void pictureBox3_MouseMove(object sender, MouseEventArgs e)
              {
                  if (draw)
                  {
                      Image pic = pictureBox3.Image;
                      Bitmap bmp = new Bitmap(pic);
                      Graphocs g = Graphics.FromImage(bmp);
                      g.FillEllipse(color, e.X, e.Y, 5, 5);
                      pictureBox3.Image = bmp;
                  }
              }

      Comment

      Working...