I have an image data field in a datarow (as in the Northwinds demo sql
database). What is the C# instruction syntax to display it in a Winform
picturebox control.
--
GSSI 14 9886
Hi,
You have to create a bitmap first
Save your image to either a temp file or to a memory stream. then use the
correct constructor of Bitmat
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"GSSI" <GS**@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com... I have an image data field in a datarow (as in the Northwinds demo sql database). What is the C# instruction syntax to display it in a Winform picturebox control. -- GSSI
Hi GSSI,
You need to remove the sql image type header before you try to do anything with the data.
Feed the byte[] to a MemoryStream. Set the position of the MemoryStream to 78 (I think this is the size of the header). Then use Image.FromStream(MemoryStream)
On Mon, 10 Apr 2006 17:10:02 +0200, GSSI <GS**@discussions.microsoft.com> wrote: I have an image data field in a datarow (as in the Northwinds demo sql database). What is the C# instruction syntax to display it in a Winform picturebox control.
--
Happy coding!
Morten Wennevik [C# MVP]
Hi,
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:op.s7sun1fhklbvpo@stone... Hi GSSI,
You need to remove the sql image type header before you try to do anything with the data. Feed the byte[] to a MemoryStream. Set the position of the MemoryStream to 78 (I think this is the size of the header). Then use Image.FromStream(MemoryStream)
I have never deal with a header in the image (or binary data) from SQL , I
store documents in an Image field and I have never need to remove any part
of it.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
I'm pretty green at this. How do I get the data field into a byte array?
--
GSSI
"Morten Wennevik" wrote: Hi GSSI,
You need to remove the sql image type header before you try to do anything with the data. Feed the byte[] to a MemoryStream. Set the position of the MemoryStream to 78 (I think this is the size of the header). Then use Image.FromStream(MemoryStream)
On Mon, 10 Apr 2006 17:10:02 +0200, GSSI <GS**@discussions.microsoft.com> wrote:
I have an image data field in a datarow (as in the Northwinds demo sql database). What is the C# instruction syntax to display it in a Winform picturebox control. -- Happy coding! Morten Wennevik [C# MVP]
Ok, usually you don't have to deal with the header, but if you are using the Northwind sample database, you do. If you aren't using the Northwind database, and are unaware of any header info don't adjust the position before loading the image.
On Mon, 10 Apr 2006 19:05:28 +0200, Ignacio Machin ( .NET/ C# MVP ) <ignacio.machin AT <dot.state.fl.us>> wrote: Hi,
"Morten Wennevik" <Mo************@hotmail.com> wrote in message news:op.s7sun1fhklbvpo@stone... Hi GSSI,
You need to remove the sql image type header before you try to do anything with the data. Feed the byte[] to a MemoryStream. Set the position of the MemoryStream to 78 (I think this is the size of the header). Then use Image.FromStream(MemoryStream)
I have never deal with a header in the image (or binary data) from SQL , I store documents in an Image field and I have never need to remove any part of it.
--
Happy coding!
Morten Wennevik [C# MVP]
Well, you need to query the database. This example might be helpful.
[How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET] http://support.microsoft.com/default...b;en-us;309158
Following the sample you will end up with
MyData = (byte[])myRow["imgField"];
Continue with this
using(MemoryStream ms = new MemoryStream(MyData))
{
Image img = Image.FromStream(ms);
}
On Mon, 10 Apr 2006 19:18:02 +0200, GSSI <GS**@discussions.microsoft.com> wrote: I'm pretty green at this. How do I get the data field into a byte array?
--
Happy coding!
Morten Wennevik [C# MVP]
Morten, much appreciative of your help. It's almost working but still getting
an exception when I try to load the image into the control. Code is ...
"byte[] picByte = (byte[])(drUR[0]["Picture"]);
MemoryStream msPic = new MemoryStream(picByte);
msPic.Position=78;
pictureBox1.Image = (Image)Image.FromStream(msPic);"
Any thoughts?
--
GSSI
"Morten Wennevik" wrote: Well, you need to query the database. This example might be helpful.
[How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET] http://support.microsoft.com/default...b;en-us;309158
Following the sample you will end up with
MyData = (byte[])myRow["imgField"];
Continue with this
using(MemoryStream ms = new MemoryStream(MyData)) { Image img = Image.FromStream(ms); }
On Mon, 10 Apr 2006 19:18:02 +0200, GSSI <GS**@discussions.microsoft.com> wrote:
I'm pretty green at this. How do I get the data field into a byte array? -- Happy coding! Morten Wennevik [C# MVP]
Hi,
is dr a datatable?
What is the error you are getting?
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Ignacio:
drUR is a datarow[].
All variables seem to be initializing correctly. Moreover, that data seems
to be formatted correctly. (I can verify this by using a simple Access form
with a PictureBox control connected via an Access Project setup.)
I don't get an explicit error message because of a surrounding try/catch
construct.
--
GSSI
"Ignacio Machin ( .NET/ C# MVP )" wrote: Hi,
is dr a datatable?
What is the error you are getting?
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
Don't set the position if you aren't using the Northwind database.
On Mon, 10 Apr 2006 20:21:02 +0200, GSSI <GS**@discussions.microsoft.com> wrote: Morten, much appreciative of your help. It's almost working but still getting an exception when I try to load the image into the control. Code is ...
"byte[] picByte = (byte[])(drUR[0]["Picture"]); MemoryStream msPic = new MemoryStream(picByte); msPic.Position=78; pictureBox1.Image = (Image)Image.FromStream(msPic);"
Any thoughts?
--
Happy coding!
Morten Wennevik [C# MVP]
Hi,
Well, what are you getting in the catch ?????
Unless you post the error message I have no idea why you are having this
problem.
Also see if the InnerException is populated
BTW, did you try to save the image to disk and read the file back?
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"GSSI" <GS**@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com... Ignacio:
drUR is a datarow[]. All variables seem to be initializing correctly. Moreover, that data seems to be formatted correctly. (I can verify this by using a simple Access form with a PictureBox control connected via an Access Project setup.)
I don't get an explicit error message because of a surrounding try/catch construct. -- GSSI
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,
is dr a datatable?
What is the error you are getting?
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
Ignacio:
The Error Message is "INVALID PARAMETER USED.". The Inner Exception is null.
Yes, I have copied the field to disk and have been able to display it in
Paint.
Sorry for being so clutsy!
--
GSSI
"Ignacio Machin ( .NET/ C# MVP )" wrote: Hi,
Well, what are you getting in the catch ?????
Unless you post the error message I have no idea why you are having this problem. Also see if the InnerException is populated
BTW, did you try to save the image to disk and read the file back?
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation "GSSI" <GS**@discussions.microsoft.com> wrote in message news:42**********************************@microsof t.com... Ignacio:
drUR is a datarow[]. All variables seem to be initializing correctly. Moreover, that data seems to be formatted correctly. (I can verify this by using a simple Access form with a PictureBox control connected via an Access Project setup.)
I don't get an explicit error message because of a surrounding try/catch construct. -- GSSI
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,
is dr a datatable?
What is the error you are getting?
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
Morten: I AM using the Northwind database!
That's why I am so frustrated. In MS Access Project, it is a simple matter
to simply point a PictureBox control at an image and it will display it. I
don't expect C# and Winforms to be that much more complicated.
--
GSSI
"Morten Wennevik" wrote: Don't set the position if you aren't using the Northwind database.
On Mon, 10 Apr 2006 20:21:02 +0200, GSSI <GS**@discussions.microsoft.com> wrote:
Morten, much appreciative of your help. It's almost working but still getting an exception when I try to load the image into the control. Code is ...
"byte[] picByte = (byte[])(drUR[0]["Picture"]); MemoryStream msPic = new MemoryStream(picByte); msPic.Position=78; pictureBox1.Image = (Image)Image.FromStream(msPic);"
Any thoughts? -- Happy coding! Morten Wennevik [C# MVP]
Hi, The Error Message is "INVALID PARAMETER USED.". The Inner Exception is null.
Yes, I have copied the field to disk and have been able to display it in Paint.
Sorry for being so clutsy!
What if you keep a reference to the MemoryStream in a member variable, IIRC
you need to have the stream available always.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stephen Williams |
last post by:
Does Microsoft have a comment the possible bug on the
PictureBox Class. Here is the exchange I had on the
Experts-Exchange regarding this issue:
From Z_Beeblebrox:
Hi,
I believe it is...
|
by: David Ricker |
last post by:
I have created a PictureBox control which can have it's Image property
directly bound to an image field in a database. This works perfectly for
showing the images that are in the database. When I...
|
by: BrianW |
last post by:
I am working on a program that has multiple picturebox controls that a user
is allowed to move around which are contained within a panel control for
visual placement. In my mousedown event, I set...
|
by: Segfahlt |
last post by:
I need a little help here please.
I have 2 win forms user controls in 2 different projects that I'm hosting in
2 different virtual directories. The controls have been test and operate okay
in...
|
by: munglet |
last post by:
Is there anyway to get a picturebox to recieve focus?
I ask because I implemented a "delete" button in a picturebox (due to
size constraints), but now due to accessibility reasons I need to be...
|
by: GoGs |
last post by:
How this vb6 code convert in c# dotnet2
-----
Image1.Visible = False
Image1.Picture = LoadPicture("c:\image008.jpg")
Dim x, y As Single
x = Image1.Width
y = Image1.Height
Do While x...
|
by: kirk |
last post by:
I have a form with a PictureBox control on it. The .Image property is
set to a PNG file(which shows the picture of the US map) with some
transparency in it. The .BackColor property is set to...
|
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...
|
by: leshka82 |
last post by:
I have recently designed a Winform Image drag & drop utility. The approach I took was to have a Panel control serve as a destination for multiple file drop. Once the user dragged & dropped the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
| |