Save image to sql.

Hello, lately I have been triying to create a code to upload an image into my sql database from visual cobol 2012. I have done this in C# with 

byte[] image
object o = Clipboard.GetDataObject().GetData("Bitmap");
if (o != null)
{
pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox.Image = (Image)o;
}

using (MemoryStream ms = new MemoryStream())
{
pictureBox.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
image = ms.ToArray();
}

Im not sure how I can do " pictureBox.Image = (Image)o;"  in visual cobol, since im stuck there I haven't tried to code the rest but I don't think that would be any problem.

How can I manage to do this task in visual cobol? 

Parents
  • I managed to save the image into SQL using this code.

                  set pbImage::Image to type System.Windows.Forms.Clipboard::GetImage()

                  set pbImage::SizeMode to type System.Windows.Forms.PictureBoxSizeMode::Zoom

                  invoke pbImage::Image::Save("temp-img", type System.Drawing.Imaging.ImageFormat::Jpeg)

                  set fil to type System.IO.FileStream::New("temp-img", type System.IO.FileMode::Open)

                  set size of aBytes to fil::Length

                  invoke fil::Read(aBytes, 0, aBytes::Count())

                  invoke sql-db::itm-img-to-sql(txtTest::Text, aBytes)

    The image i want to upload doesnt come from a file but from a picturebox. Since the sample only shows how to upload from image I save the image to a temporary file then upload from file.

Reply
  • I managed to save the image into SQL using this code.

                  set pbImage::Image to type System.Windows.Forms.Clipboard::GetImage()

                  set pbImage::SizeMode to type System.Windows.Forms.PictureBoxSizeMode::Zoom

                  invoke pbImage::Image::Save("temp-img", type System.Drawing.Imaging.ImageFormat::Jpeg)

                  set fil to type System.IO.FileStream::New("temp-img", type System.IO.FileMode::Open)

                  set size of aBytes to fil::Length

                  invoke fil::Read(aBytes, 0, aBytes::Count())

                  invoke sql-db::itm-img-to-sql(txtTest::Text, aBytes)

    The image i want to upload doesnt come from a file but from a picturebox. Since the sample only shows how to upload from image I save the image to a temporary file then upload from file.

Children
No Data