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
  • The following code should work:

       declare image as type Byte occurs any
       declare o as object = type Clipboard::GetDataObject()::GetData("Bitmap");
       if o not = null
          set pictureBox1::SizeMode to type PictureBoxSizeMode::StretchImage
          set pictureBox1::Image to o as type Image
          perform using ms as type System.IO.MemoryStream = new System.IO.MemoryStream
            invoke pictureBox1::Image::Save(ms, type System.Drawing.Imaging.ImageFormat::Jpeg)
            set image to ms::ToArray
          end-perform
       end-if
    
Reply
  • The following code should work:

       declare image as type Byte occurs any
       declare o as object = type Clipboard::GetDataObject()::GetData("Bitmap");
       if o not = null
          set pictureBox1::SizeMode to type PictureBoxSizeMode::StretchImage
          set pictureBox1::Image to o as type Image
          perform using ms as type System.IO.MemoryStream = new System.IO.MemoryStream
            invoke pictureBox1::Image::Save(ms, type System.Drawing.Imaging.ImageFormat::Jpeg)
            set image to ms::ToArray
          end-perform
       end-if
    
Children
No Data