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
Marvin ReidPosted Aug 3, 2023, 6:41 PM
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:
https://www.leadtools.com/help/sdk/tutorials/dotnet-console-load-and-save-images.html
Prabhu RajaPosted Oct 3, 2011, 8:44 AM
byte[] data= (byte[]) dr[0]; // check data is null or not by using Breakpoint.
mansoor altafPosted Oct 3, 2011, 8:32 AM
Prabhu RajaPosted Oct 3, 2011, 8:22 AM
Bitmap myImage=Bitmap.FromStream(ms);
To
Image myImage=Image.FromStream(ms);
mansoor altafPosted Oct 3, 2011, 8:08 AM
Prabhu RajaPosted Oct 3, 2011, 1:58 AM
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 altafPosted Oct 3, 2011, 1:39 AM
Prabhu RajaPosted Oct 1, 2011, 4:57 AM
--------------------------------------------------------------
If this helps you, then mark as "Correct Answer"
Thank You