hi.
i have selected the image using openfiledialog and loaded it to the picturebox in c# desktop app.
now i want to save the image, while saving the image it raises the exception that [] , these brackets are invalid parameters.
my code is.
MemoryStream stream=new MemoryStream();
pictureBox1.Image.Save(stream,System.Drawing.Imaging.ImageFormat.Jpeg);
pic=stream.ToArray();
here pic is of byte[] type. which is class level variable.
then i store pic in insert query like this.
string str = "insert into branches (branchcode,branchname,address,landlinecell,picture,description) values(" + branchcode + ",'" + branchname + "','" + address + "','" + landline + "'," + @pic+ ",'" + description + "')";
and then send the query to my save method to do the insertion operation.
what is the problem??
Loading

Prabhu RajaRank #861 · 2.6K reputationPosted Oct 1, 2011, 12:57 AM EDT
--------------------------------------------------------------
If this helps you, then mark as "Correct Answer"
Thank You
mansoor altaf67 reputationPosted Oct 2, 2011, 9:39 PM EDT
Prabhu RajaRank #861 · 2.6K reputationPosted Oct 2, 2011, 9:58 PM EDT
con.open();
SqlCommand cmd = new SqlCommand("SELECT pictureColumn FROM TableName", cn); //Change According to Your needs
SqlDataReader dr;
{
// Get Image as
-----------------------------------------------------------
If this helps you, then mark as "Correct Answer"
Thank You
mansoor altaf67 reputationPosted Oct 3, 2011, 4:08 AM EDT
Prabhu RajaRank #861 · 2.6K reputationPosted Oct 3, 2011, 4:22 AM EDT
Bitmap myImage=Bitmap.FromStream(ms);
To
Image myImage=Image.FromStream(ms);
mansoor altaf67 reputationPosted Oct 3, 2011, 4:32 AM EDT
Prabhu RajaRank #861 · 2.6K reputationPosted Oct 3, 2011, 4:44 AM EDT
byte[] data= (byte[]) dr[0]; // check data is null or not by using Breakpoint.
Marvin ReidRank #1,963 · 746 reputationPosted Aug 3, 2023, 2:41 PM EDT
Another solution is you can use the RasterCodecs class to load and save your file using the byte array. After conversion you can then pass the stream output for use in the database. Here is some quick code that demonstrates this:
byte[] bytes = File.ReadAllBytes(@"Path to file"); using (MemoryStream ms = new MemoryStream(bytes)) { RasterCodecs codecs = new RasterCodecs() ms.Position = 0; RasterImage image = codecs.Load(ms); // Image loaded from memory codecs.Save(image, ms, RasterImageFormat.Jpeg, 0); // Save to memory }https://www.leadtools.com/help/sdk/tutorials/dotnet-console-load-and-save-images.html