473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

picturebox and access DB help

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
5 2051
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ed Landau | last post by:
In VB6.0, I can put an image on a form and assign it's .picture property at run-time. In VBA (within MS Access), when I put down an image control on a form, it asks me for the source to the image...
5
by: Mike Dole | last post by:
When I am updating a picturebox with an image (extracted) from an access database I keep getting a "The process cannot access the file "c:\foto1.jpg because it is being used by another process"...
0
by: akh | last post by:
I want to use de Drag and Drop ´s event to move a picture box from a form and within a Picture Box. But I have behaviour if the MyPBox As PictureBox as the Globale varible or not Thanks for...
2
by: Mattbooty | last post by:
Hello, Not sure if anyone else has seen this bug, but I have a form where the entire form is covered with a picturebox. The picturebox has a mouseup event. I also have an open file dialog for...
3
by: Radu | last post by:
Hi. I need to use a PictureBox ctl (as in VB) - the picturebox should have at least the CLS method, and the backcolor AND forecolor properties. The "Image" control is therefore not what I need....
7
by: kebalex | last post by:
Hi, I have an app (written in .NET 2.0) which updates a picturebox according to some user input (a slider control). when the user makes a change i loop through all of the pixels, do a...
4
by: munibe | last post by:
Hi, i have a problem about picturebox control. if you may help me, i will be so happy. i have a picturebox named pic_map, and i added a button named customer_button, my wish is to add a new small...
4
by: Jim McGivney | last post by:
In C# on Form1 I genetate an array of PictureBoxes and populate each with an image as seen in the code below. Later on I want to access a specific PictureBox to change its image, but I keep...
4
by: gerardianlewis | last post by:
Any help appreciated. (VB.NET under XP and Vista, SP1 installed) My code, inherited from a VB6 version of an app that ran under W98, loads an image from a file into a PictureBox. The user may...
5
by: AWW | last post by:
XP VB 2005 running an example from help that creates a picturebox in code - the picturebox is not created. If I comment out the "Dim Box as New PictureBox" and create it in Design mode - the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.