By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,854 Members | 869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,854 IT Pros & Developers. It's quick & easy.

picturebox and access DB help

P: n/a
Hi ,
I'm trying to show a bitmap I pasted on an Access DB, but when I try to
convert the memorystream to bitmap I get an error, can any one help me
out ??
Thanks a lot.
Paolo L.

Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Paolol, we really need to know what the error is to be able to help. How
about posting the complete text and the code that caused it.

--
Greg Ewing [MVP]
http://www.citidc.com

"Paolol" <pa***********@salsan.net> wrote in message
news:er**************@tk2msftngp13.phx.gbl...
Hi ,
I'm trying to show a bitmap I pasted on an Access DB, but when I try to
convert the memorystream to bitmap I get an error, can any one help me
out ??
Thanks a lot.
Paolo L.

Nov 15 '05 #2

P: n/a
Thanks Greg, this is the code I got some of this from a project I
founded in Internet, when I use the DrawToScale function or I try to set
the Image ( both are commented out ) I get the same error " invalid
argument " ????
I was not able to find any wrong argument in the code, but I'm new to C#
so please help me out :))
Thanks,
Paolo L.
---------------------
private void dataGrid1_Click(object sender, System.EventArgs e)
{
try
{
iIDListview =
System.Convert.ToInt32(this.dataGrid1[dataGrid1.CurrentRowIndex,0].ToString());
string sString = this.dataGrid1[dataGrid1.CurrentRowIndex,1].ToString();
//this.oleDbDataAdapter2.Fill(this.dsImmage11);
this.oleDbConnection1.Open();
this.oleDbDataAdapter2.SelectCommand.Parameters[0].Value=sString.Trim();
byte[] bB = (byte[])
this.oleDbDataAdapter2.SelectCommand.ExecuteScalar ();
if (bB.Length > 0 )
{
System.IO.MemoryStream Stream1 = new System.IO.MemoryStream(bB,true);
Stream1.Write(bB,78,bB.Length-78 );
//
//pictureBox1.Image = Image.FromStream(Stream1,true);
//DrawToScale(Image.FromStream(Stream1,false));

//
Stream1.Close();
}//if*/
// caricamento dettagli
this.oleDbDataAdapter3.SelectCommand.Parameters[0].Value= iIDListview;
this.oleDbDataAdapter3.Fill(this.dsDetail1);
this.oleDbDataAdapter4.SelectCommand.Parameters[0].Value= iIDListview;
this.oleDbDataAdapter4.Fill(this.dsDetLoc1);
this.oleDbDataAdapter5.SelectCommand.Parameters[0].Value= iIDListview;
this.oleDbDataAdapter5.Fill(this.dsDetMove1);
//
}
catch (Exception eE)
{
MessageBox.Show(eE.Message);
}
finally
{
this.oleDbConnection1.Close();
}
}
private void DrawToScale(Image bmp)
{
// The client rectangle
Rectangle rc = pictureBox1.ClientRectangle;

// From Programming Windows with C#, by Charles Petzold
// Figure out the scaling necessary for the image
SizeF size = new SizeF( bmp.Width / bmp.HorizontalResolution,
bmp.Height / bmp.VerticalResolution);
float fScale = Math.Min( rc.Width / size.Width, rc.Height / size.Height);

size.Width *= fScale;
size.Height *= fScale;

// Create a new bitmap of the proper size for the existing bitmap
// and assign it to the picture box
pictureBox1.Image = new Bitmap(bmp, size.ToSize());
}

---------------------

Greg Ewing [MVP] wrote:
Paolol, we really need to know what the error is to be able to help. How
about posting the complete text and the code that caused it.


Nov 15 '05 #3

P: n/a
Paolol, first thing I would try is resetting Stream1 back to the beginning.
After calling Write on a stream the current position is set to the end of
the bytes written. When you pass that stream in to the Image methods then
it is not valid information.

Hope that helps.

--
Greg Ewing [MVP]
http://www.citidc.com

"Paolol" <pa***********@salsan.net> wrote in message
news:OO**************@TK2MSFTNGP10.phx.gbl...
Thanks Greg, this is the code I got some of this from a project I
founded in Internet, when I use the DrawToScale function or I try to set
the Image ( both are commented out ) I get the same error " invalid
argument " ????
I was not able to find any wrong argument in the code, but I'm new to C#
so please help me out :))
Thanks,
Paolo L.
---------------------
private void dataGrid1_Click(object sender, System.EventArgs e)
{
try
{
iIDListview =
System.Convert.ToInt32(this.dataGrid1[dataGrid1.CurrentRowIndex,0].ToString(
)); string sString = this.dataGrid1[dataGrid1.CurrentRowIndex,1].ToString();
//this.oleDbDataAdapter2.Fill(this.dsImmage11);
this.oleDbConnection1.Open();
this.oleDbDataAdapter2.SelectCommand.Parameters[0].Value=sString.Trim();
byte[] bB = (byte[])
this.oleDbDataAdapter2.SelectCommand.ExecuteScalar ();
if (bB.Length > 0 )
{
System.IO.MemoryStream Stream1 = new System.IO.MemoryStream(bB,true);
Stream1.Write(bB,78,bB.Length-78 );
//
//pictureBox1.Image = Image.FromStream(Stream1,true);
//DrawToScale(Image.FromStream(Stream1,false));

//
Stream1.Close();
}//if*/
// caricamento dettagli
this.oleDbDataAdapter3.SelectCommand.Parameters[0].Value= iIDListview;
this.oleDbDataAdapter3.Fill(this.dsDetail1);
this.oleDbDataAdapter4.SelectCommand.Parameters[0].Value= iIDListview;
this.oleDbDataAdapter4.Fill(this.dsDetLoc1);
this.oleDbDataAdapter5.SelectCommand.Parameters[0].Value= iIDListview;
this.oleDbDataAdapter5.Fill(this.dsDetMove1);
//
}
catch (Exception eE)
{
MessageBox.Show(eE.Message);
}
finally
{
this.oleDbConnection1.Close();
}
}
private void DrawToScale(Image bmp)
{
// The client rectangle
Rectangle rc = pictureBox1.ClientRectangle;

// From Programming Windows with C#, by Charles Petzold
// Figure out the scaling necessary for the image
SizeF size = new SizeF( bmp.Width / bmp.HorizontalResolution,
bmp.Height / bmp.VerticalResolution);
float fScale = Math.Min( rc.Width / size.Width, rc.Height / size.Height);

size.Width *= fScale;
size.Height *= fScale;

// Create a new bitmap of the proper size for the existing bitmap
// and assign it to the picture box
pictureBox1.Image = new Bitmap(bmp, size.ToSize());
}

---------------------

Greg Ewing [MVP] wrote:
Paolol, we really need to know what the error is to be able to help. How about posting the complete text and the code that caused it.

Nov 15 '05 #4

P: n/a
Hi Greg,
thanks for the help, at last I found the error, it was in the immage i
stored in Access, I deleted the old one and drop a new one from "Paint"
( cut/paste ) and now it works.
Did you have nay idea why this happen, in the Access Form I use to enter
the image all was showing OK ??
Again Thanks.
Paolo L.

Greg Ewing [MVP] wrote:
Paolol, first thing I would try is resetting Stream1 back to the beginning.
After calling Write on a stream the current position is set to the end of
the bytes written. When you pass that stream in to the Image methods then
it is not valid information.

Hope that helps.


Nov 15 '05 #5

P: n/a
Paolol, no, I don't have any idea why it wouldn't work. Glad it is though.

--
Greg Ewing [MVP]
http://www.citidc.com

"Paolol" <pa***********@salsan.net> wrote in message
news:uG*************@TK2MSFTNGP09.phx.gbl...
Hi Greg,
thanks for the help, at last I found the error, it was in the immage i
stored in Access, I deleted the old one and drop a new one from "Paint"
( cut/paste ) and now it works.
Did you have nay idea why this happen, in the Access Form I use to enter
the image all was showing OK ??
Again Thanks.
Paolo L.

Greg Ewing [MVP] wrote:
Paolol, first thing I would try is resetting Stream1 back to the beginning. After calling Write on a stream the current position is set to the end of the bytes written. When you pass that stream in to the Image methods then it is not valid information.

Hope that helps.

Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.