Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys when i retrieving the signature from sql server of ink picture which i have inserted like...

C#
string rowsid = GlobalClass.rowsID;
image.Save(Application.StartupPath + @"\Signature\" + "Out" + "+" + GlobalClass.RepName + "+" + rowsid + ".JPG");

and trying to retrieve from sql server like...

C#
if (dr.Read())
{
    textBox2.Text = dr[7].ToString();
    textBox5.Text = dr[12].ToString();
    textBox3.Text = dr[10].ToString();
    textBox4.Text = dr[11].ToString();
    
    byte[] buffer = (byte[])dr[45];
    
    MemoryStream strm = new MemoryStream(buffer);
    strm.Write(buffer, 0, buffer.Length);
    strm.Position = 0;
    
    Image img = Image.FromStream(strm);
    pictureBox1.Image = Image.FromStream(strm);//errorinvalid parameter



when i trying to show the image into picture box i m getting the error invalid parameter as write above in bold...
may i know how can i solve this problem...please help me..
Posted
Updated 5-Feb-12 10:05am
v2
Comments
Sriram Chitturi 5-Feb-12 15:57pm    
a) What is the Type of the SQL server column 45?
b) You are creating a stream to the buffer and writing to the buffer back why?
also
c) what are you saving to in image.Save(...) call ?

If you want to read from that file, then call Image.FromFile()
LanFanNinja 5-Feb-12 17:41pm    
One thing I noticed is this
Image img = Image.FromStream(strm);
pictureBox1.Image = Image.FromStream(strm);//errorinvalid parameter

Why are you doing this?

Why not just do this
Image img = Image.FromStream(strm);
pictureBox1.Image = img;
Rajendra Koranga 5-Feb-12 23:50pm    
hi Sriram,
a) image is the type of the sql server column 45
b)coz i have seen in google search earlier.and code like this is also giveing the error invalid parameter


Image img = Image.FromStream(strm);
pictureBox1.Image = img;

my prob is i have inserted the inkpicture image in the sql server in .isf format..and trying to retrieve the binary data which is showing in the database in picture box..so can u please help me to send the code...
i have check all the code of everyone which is giving error ..how can i check the the format of data which i have saved in the database i think its not a image data...but my type of the field is image...
LanFanNinja 6-Feb-12 0:38am    
OK so I am looking through your code and there is certainly somethings that are confusing me!

It looks like you are getting the image data on this line
byte[] buffer = (byte[])dr[45];

and then on this line you are writing the data to the buffer again!?!?
strm.Write(buffer, 0, buffer.Length);

so as said in Solution 1 and Solution 2 these two lines are unnecessary
strm.Write(buffer, 0, buffer.Length);
strm.Position = 0;

I wrote an example for you to check out maybe it will help you to figure something out. Maybe you will figure out that the data you are getting on this line

byte[] buffer = (byte[])dr[45];

is not your image data or at least not all of it or perhaps more than all of it.

MSDN says the File.FromStream() method will throw an ArgumentException if the stream does not have a valid image format or is null.

You also said in another comment
"i have inserted the inkpicture image in the sql server in .isf format"
what is this isf format?
I am all but certain the PictureBox control does not support it!

Anyway here is my example.
NOTE: "test.jpg" is just some random image i have on my hard drive.

Bitmap img = new Bitmap("test.jpg");
byte[] imgData = (byte[])TypeDescriptor.GetConverter(img).ConvertTo(img, typeof(byte[]));

MemoryStream ms = new MemoryStream(imgData);
Bitmap bmp = (Bitmap)Bitmap.FromStream(ms);

pictureBox1.Image = bmp;

Good luck.

P.S. I am sorry if non of this make any sense. I am so tired right now that I think I just saw some cartoon looking guy walking around my room to the left of me. =0
Rajendra Koranga 7-Feb-12 0:14am    
ohh i m streamly sorry its not .isf its .gif..
actually i am inserted the ink picture and its signature by pen tablet in gif format . should i covert the .gif format into .jpg format
and sir my image is not in my hard drive its in sqlserver..


thanks a lot to help me

Can you try removing these lines
C#
strm.Write(buffer, 0, buffer.Length);
strm.Position = 0;
 
Share this answer
 
Comments
Rajendra Koranga 6-Feb-12 0:05am    
i have remove sir but still its giving error at
Image img = Image.FromStream(strm);//invalid parameter
Image img = Image.FromStream(strm);
pictureBox1.Image = Image.FromStream(strm);//errorinvalid parameter

If img is an image, then the issue is that you've used the stream to create an image, so why are you not setting img to be your picturebox image ? Also, why are all your variable names the default, and therefore hard to read and meaningless ? Why are you reading SQL in the presentation layer ? There's a lot of issues in this code.

The other guy is right, your code has passed the buffer in, it doesn't need to read it again. your code looks like you are guessing.

Just to add, the fact that the img = xxx line does not blow up, tells me your stream is valid. If it blew up, I'd assume your stream is not valid.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900