473,666 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bind Image Data to PicBox

Hi,
I'm just getting started w/ VB.NET. I've been doing database development in
MS Access, both as Access databases or as a front end for SQL Server. I need
to create a VB.NET app to do some specific functions with SQL Server data.
The main problem I'm having is trying to bind data from a SQL Server image
data type field to a PictureBox control. For example, the image data field
in my table will hold a JPG file of a scanned document (file size probably no
greater than 300KB). I just want to be able to display the JPG in a
PictureBox control after a user enters some kind of parameter to return a
specific record. I just can't seem to get it right. I left a message in a
SQL Server forum and was told to try here.
Any help would be greatly appreciated!!!
--
PaulJS
Nov 21 '05 #1
3 3910
Hi,

Images are stored in a database as an array of byte. To convert an
array of byte to a bitmap you read the byte array in to a memory stream and
create a bitmap from it. I created an Video Capture Box which adds a
ByteImage property to a picture box which you can bind to. You can download
it from gotdotnet
http://www.gotdotnet.com/Community/U...3-c664ae2f91f8

VideoCapture1.D ataBindings.Add ("ByteImage" , dt, "Picture")

Ken
---------------
"PaulJS" <Pa****@discuss ions.microsoft. com> wrote in message
news:A7******** *************** ***********@mic rosoft.com...
Hi,
I'm just getting started w/ VB.NET. I've been doing database development in
MS Access, both as Access databases or as a front end for SQL Server. I
need
to create a VB.NET app to do some specific functions with SQL Server data.
The main problem I'm having is trying to bind data from a SQL Server image
data type field to a PictureBox control. For example, the image data field
in my table will hold a JPG file of a scanned document (file size probably
no
greater than 300KB). I just want to be able to display the JPG in a
PictureBox control after a user enters some kind of parameter to return a
specific record. I just can't seem to get it right. I left a message in a
SQL Server forum and was told to try here.
Any help would be greatly appreciated!!!
--
PaulJS
Nov 21 '05 #2
Paul,

You use the word Bind image. What means in terms of VBNet that you have a
kind of datasource that is a collection or a datatable.

From your text however I get an other idea. Can you tell us more what you
mean where comes the picture from and how do you get it..

Cor
Nov 21 '05 #3
Hi Cor,

Yes, thank you, it really did!

I´ve been brooding on this problem for some time now.
Thanks to your hints I came up with the following code in C#,
which works OK for me. But I´m actually not using Binding ...

I have a small MS Access DB called BMprov.mdb for trial.
It contains only one table called PicTest, and this table
contains only three columns:
PicNo (numeric runing number)
Name (character string)
PicDraw (bitmap picture, an ActiveX-object derived from a jpg-file in the MS
Access environment).

Here is the essential code:

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Data.Ole Db;
using System.IO;

.....

public void runPicture(stri ng picNo)
{
// ICa 2005-06-03 20:38
Cursor tmp = this.Cursor;
this.Cursor = Cursors.WaitCur sor;

try
{
OleDbConnection picC = new OleDbConnection ();
picC.Connection String = "Provider=Micro soft.JET.OLEDB. 4.0;" + @"data
source = C:\Waterials\Da tabas\BMprov.md b";
picC.Open();

string sqlString = "SELECT * FROM PicTest WHERE PicNo = " + picNo;
OleDbDataAdapte r picA = new OleDbDataAdapte r (sqlString, picC);
OleDbCommandBui lder picB = new OleDbCommandBui lder(picA);
DataSet picD = new DataSet();
picA.Fill(picD, "PicTest");
DataTable picT = picD.Tables["PicTest"];

txPicNo.Text = picT.Rows[0]["PicNo"].ToString();
txName.Text = picT.Rows[0]["Name"].ToString();

Byte[] draw = (Byte[]) picT.Rows[0]["PicDraw"];
MemoryStream ms = new MemoryStream(dr aw, 78, draw.Length -78);
pbDrawing.Image = Image.FromStrea m(ms);
ms.Close();
}
catch (Exception ex)
{
MessageBox.Show ("Fel vid framtagning av bild: " + ex.Message,
"Bild-fel", MessageBoxButto ns.OK,

MessageBoxIcon. Error);
}
this.Cursor = tmp;
}

It sure took me some good time to figure all this out ...

Best regards
/Jingo
"Cor Ligthert" wrote:
Paul,

First of all do I when I have this kind of problems create some extra steps
in my code.
Now it is nice connected however hard to debug and even more difficult to
show to somebody else.

Secondly, I don't see the reason for the binding in this. You use a "next
button".

Here a piece from a program from me, not a sample, so I cannot show it
complete because that will be to much.
\\\
Private Sub btnNext_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles btnNext.Click
If number < dsFototabel.Tab les(0).Rows.Cou nt - 1 Then
number += 1
setPicture()
End If
End Sub
///

And then there is in fact nothing more than

\\\
arrPicture = CType(dsFototab el.Tables(0).Ro ws(number)("thu mb"), Byte())
ms = New MemoryStream(ar rPicture)
picCurrent.Imag e = Image.FromStrea m(ms)
///

However it can as well be that you are using OLE pictures, than you have to
set (hopefully because there are more formats in that)

\\\
Dim ms1 As New System.IO.Memor yStream(arrPict ure, 78, arrPicture.Leng th -
78)
///

I hope this helps a little bit?

Cor

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5144
by: halise irak via .NET 247 | last post by:
I get an "ArgumentException: Invalid parameter used at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement)" exception. it is too ridicilious to get such an exception, can anyone see what might cause that exception? (By the way, i am trying to throw the header part of the image away and extract only
3
29935
by: Shailaja Kulkarni | last post by:
hi All, This problem is for C# windows application. I have a user control whcih contains one picture box along with other controls. Depending on certain conditions I want to change images on the picturebox. But at the same time I want to refer only assembly of the user control in other solution. If I am using method System.Drawing.Image.FromFile("filename") I have to put gif files containing those images in bin directory of solution in...
2
3205
by: Crirus | last post by:
hello I have apicturebox painted in it's paint event. I need a way to save the image created. Image obj of my picturebox is Nothing. How to output to a jpg my image? Crirus
7
1681
by: Adam Maltby | last post by:
Hi, I am adding an new picbox and animated gif to it at runtime Dim img As Image = Image.FromFile(Application.StartupPath & "\animation.gif") With pic_Wait .Location = New Point(300, 250) .Width = 72 .Height = 101 .BackColor = Color.Transparent .BorderStyle = BorderStyle.None
7
11614
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an OpenFileDialog: Dim result As DialogResult = Pic_Sel.ShowDialog() If (result = DialogResult.OK) Then
3
4083
by: tedqn | last post by:
I'm using VS 2005. When user selects a image from the FileListBox, the code is PictureBox.ImageLocation = sFullPath PictureBox is set to AutoSize. When the newly loaded image is smaller than the panel size, I want to center it within the panel by calculating and move the box to a location other than (0,0). The
2
1594
by: sanju | last post by:
Hi, I am struggling to replace a bit value 'True' or 'False' with a image true.gif or false.gif and bind it to a repeater control. I am getting values 'true' or 'false' depending on whether user is logged in or not(with asp.net membership provider) Getting true or false with this <%# Membership.GetUser(Eval("UserID")).IsOnline % and
8
2239
by: vicky87.eie | last post by:
I used a picture box to draw lines and rectangle using its graphics object in paint event. Now i need to save those lines i have drawn and print them. I need to know how to save them. I tried image.save. But i didn't work...
0
869
by: Bram2008 | last post by:
I have 2 picbox which contain lines. And i want to print it with "form.print" or "me.print". The problem is i can print the form, but the lines in picture box is gone or missing. ;). Please help me to print the form which contain picbox and its lines. NB: I use the plot line to draw a line in picbox. Thx.
0
8363
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8883
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8787
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8645
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7389
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6203
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.