I have a win form with picture box and i want to store image to database so while converting image to byte to store in database I am getting the error.How to solve the error? Here is my code and I have also pointed out the line at which error (object reference not set to instance of object) occurs:
   public string ImageToBase64(Image image,
      System.Drawing.Imaging.ImageFormat format)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            // Convert Image to byte[]
            image.Save(ms, format);-------Error at this point----
            byte[] imageBytes = ms.ToArray();
            // Convert byte[] to Base64 String
            string base64String = Convert.ToBase64String(imageBytes);
            return base64String;
        }
    }
 
    