Resolved Clipboard image to pictureBox and then to sqlite db

Kostakis45

Active member
Joined
Apr 3, 2022
Messages
37
Programming Experience
Beginner
So i guess this is a continuation to my previous post.
I'm trying to save a copied image (Clipboard) to my SQLite db via picturebox.
For now i can copy paste an image to picturebox with this code.
Paste image to picturebox:
 private void Get_Image_For_PicBox1(object sender, MouseEventArgs e)//Paste the picture to pictureBox1
        {
            if (e.Button == MouseButtons.Right)
            {             
                pictureBox1.Image = Clipboard.GetImage();             
                pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
            }
        }
once it's pasted i guess the pictureBox is no more null.But when i try to save it to database it's throwing a ANE saying parameter name 'encoder'.See Picture.This happens when it's trying to convert the image to Bytes in this converter.
Image to Bytes Converter:
public byte[] ConvertImageToBytes(Image image)
        {
            using (var stream = new MemoryStream())
            {
                image.Save(stream, image.RawFormat);//ERROR IN THIS LINE

                return stream.ToArray();
            }
        }
What am I missing?
I read that clipboard images gets RawBitmap format.Is that relative and if yes how i can resolve that?
 
Last edited:
Just resolved it by changing the ERROR line with this
Image to Bytes Converter:
class Image_Conversion
    {
        public byte[] ConvertImageToBytes(Image image)
        {
            using (var stream = new MemoryStream())
            {
                image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);//Changed this line

                return stream.ToArray();
            }
        }
 
Back
Top Bottom