473,484 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Images from OLE fields in Access database

Hi,

I'm converting a database application from Access 97 to C#/SQL Server. Old
database contains some images in OLE fields. I've figured out that there's
OLE header preceeding actual image data and dealt with some of the images
which were in standard BMP format but most of the images are in some other
format which is displayed ok in access application and can be copy/pasted to
any image editor but when doubleclicking it doesn't open any application
(like BMP images open Paint, etc.) and I can't figure out how to load it to
..NET image control. The field data for these images starts with some headers
that include two identifiable words "Picture" and "DIB". I've tried
stripping the data in many ways but nothing on my machine is able to open
these.

Does anyone has any experience with this format? Any pointers are greatly
appreciated. Otherwise I'm afraid I'm facing migration of several thousands
of images by copy/pasting from access :/

Thank you in advance,
Alan.
Nov 22 '05 #1
3 7437
Yes, you can write code to strip off the header and just get the image
bytes from the OLE fields. This code assumes that you want to load the
photo from Northwind into a PictureBox control, which I know you don't
want to do, but this is the code I happen to have lying around from
some appdev courseware that I wrote a few years back. It should be
enough to get you started:

private void LoadEmployeePhoto(int employeeID)
{
SqlDataAdapter da = null;
DataTable dt = new DataTable();
string strCnn =
"Data Source=(local);Database=Northwind;"
+ "Integrated Security=SSPI";
string strSQL =
"SELECT Photo FROM dbo.Employees"
+ " WHERE EmployeeID = "
+ employeeID.ToString();
MemoryStream msPic;
// Signature bytes of an
// OLE container header.
const byte OLEbyte0 = 21;
const byte OLEbyte1 = 28;
// Number of bytes in
// an OLE container header.
const int OLEheaderLength = 78;

da = new SqlDataAdapter(strSQL, strCnn);
da.Fill(dt);
if (dt.Rows.Count == 0)
return;

// Move binary picture data into the byte array
byte[] abytPic = (byte[])dt.Rows[0]["Photo"];

// Test for an OLE container header
if ((abytPic[0] == OLEbyte0)
&& (abytPic[1] == OLEbyte1))
{
// Use a second array to strip off the header.
// Make it big enough to hold
// the bytes after the header.
byte[] abytStripped =
new byte[abytPic.Length - OLEheaderLength];
// Strip off the header by copying the bytes
// after the header.
System.Buffer.BlockCopy(
abytPic, OLEheaderLength, abytStripped,
0, abytPic.Length - OLEheaderLength);

// Load the new byte array
// into a MemoryStream.
msPic = new MemoryStream(abytStripped);
}
else
{
// Load the original byte array into a MemoryStream
msPic = new MemoryStream(abytPic);
}
// Set the picture box image, using the stream.
picEmployee.Image = Image.FromStream(msPic);
}

--Mary

On Wed, 5 Oct 2005 20:23:19 +0300, "Alan"
<ne**@stop.spamming.ailon.org> wrote:
Hi,

I'm converting a database application from Access 97 to C#/SQL Server. Old
database contains some images in OLE fields. I've figured out that there's
OLE header preceeding actual image data and dealt with some of the images
which were in standard BMP format but most of the images are in some other
format which is displayed ok in access application and can be copy/pasted to
any image editor but when doubleclicking it doesn't open any application
(like BMP images open Paint, etc.) and I can't figure out how to load it to
.NET image control. The field data for these images starts with some headers
that include two identifiable words "Picture" and "DIB". I've tried
stripping the data in many ways but nothing on my machine is able to open
these.

Does anyone has any experience with this format? Any pointers are greatly
appreciated. Otherwise I'm afraid I'm facing migration of several thousands
of images by copy/pasting from access :/

Thank you in advance,
Alan.

Nov 22 '05 #2
Hi Mary,

I am having the same problem, but I still get a "parameter not valid" error
when I call FromStream, even after stripping off the first 78 bytes.

My images contain "Photo Editor Photo MSPhotoEd.3" followed shortly by
"MSPhotoEd.3"

These are images from an old Access database that we are moving to SQL. As
part of the process, I want to extract the embedded images to files and store
only links in the new version of the application. The images were probably
copied and pasted from a variety of image apps. Interestingly enough, I can
copy the contents of the binary field and paste it in Photoshop and get an
image, but with over 700 images, I'd rather do it programmatically.

Thanks,
Adam

Here is the part of my code that loops through the images:

For Each R As DataRow In dt1.Rows
FileNm = P & R("EmployeeID") & "_" & R("LName") & "_" & R("FName")
Dim b() As Byte
b = CType(R("Picture"), Byte())
L = 0
LB = b.Length
If LB > 0 Then
Try
Dim Stm As IO.MemoryStream

If b(0) = OLEb0 And b(1) = OLEb1 Then
Stm = New IO.MemoryStream(b, OLEHeaderLength, LB -
OLEHeaderLength)
Else
Stm = New IO.MemoryStream(b)
End If

Dim IMG As Drawing.Image
IMG = Image.FromStream(Stm)
IMG.Save(FileNm, IMG.RawFormat)

Stm.Close()
Stm.Dispose()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
Next


"Mary Chipman [MSFT]" wrote:
Yes, you can write code to strip off the header and just get the image
bytes from the OLE fields. This code assumes that you want to load the
photo from Northwind into a PictureBox control, which I know you don't
want to do, but this is the code I happen to have lying around from
some appdev courseware that I wrote a few years back. It should be
enough to get you started:

private void LoadEmployeePhoto(int employeeID)
{
SqlDataAdapter da = null;
DataTable dt = new DataTable();
string strCnn =
"Data Source=(local);Database=Northwind;"
+ "Integrated Security=SSPI";
string strSQL =
"SELECT Photo FROM dbo.Employees"
+ " WHERE EmployeeID = "
+ employeeID.ToString();
MemoryStream msPic;
// Signature bytes of an
// OLE container header.
const byte OLEbyte0 = 21;
const byte OLEbyte1 = 28;
// Number of bytes in
// an OLE container header.
const int OLEheaderLength = 78;

da = new SqlDataAdapter(strSQL, strCnn);
da.Fill(dt);
if (dt.Rows.Count == 0)
return;

// Move binary picture data into the byte array
byte[] abytPic = (byte[])dt.Rows[0]["Photo"];

// Test for an OLE container header
if ((abytPic[0] == OLEbyte0)
&& (abytPic[1] == OLEbyte1))
{
// Use a second array to strip off the header.
// Make it big enough to hold
// the bytes after the header.
byte[] abytStripped =
new byte[abytPic.Length - OLEheaderLength];
// Strip off the header by copying the bytes
// after the header.
System.Buffer.BlockCopy(
abytPic, OLEheaderLength, abytStripped,
0, abytPic.Length - OLEheaderLength);

// Load the new byte array
// into a MemoryStream.
msPic = new MemoryStream(abytStripped);
}
else
{
// Load the original byte array into a MemoryStream
msPic = new MemoryStream(abytPic);
}
// Set the picture box image, using the stream.
picEmployee.Image = Image.FromStream(msPic);
}

--Mary

On Wed, 5 Oct 2005 20:23:19 +0300, "Alan"
<ne**@stop.spamming.ailon.org> wrote:
Hi,

I'm converting a database application from Access 97 to C#/SQL Server. Old
database contains some images in OLE fields. I've figured out that there's
OLE header preceeding actual image data and dealt with some of the images
which were in standard BMP format but most of the images are in some other
format which is displayed ok in access application and can be copy/pasted to
any image editor but when doubleclicking it doesn't open any application
(like BMP images open Paint, etc.) and I can't figure out how to load it to
.NET image control. The field data for these images starts with some headers
that include two identifiable words "Picture" and "DIB". I've tried
stripping the data in many ways but nothing on my machine is able to open
these.

Does anyone has any experience with this format? Any pointers are greatly
appreciated. Otherwise I'm afraid I'm facing migration of several thousands
of images by copy/pasting from access :/

Thank you in advance,
Alan.

Dec 16 '05 #3
Hi

What if one needs a Word doc out of an access db ole container. How many
bytes is that? I heard 85, but it is not worknig for me. Any ideas here?

Thank you

"Mary Chipman [MSFT]" wrote:
Yes, you can write code to strip off the header and just get the image
bytes from the OLE fields. This code assumes that you want to load the
photo from Northwind into a PictureBox control, which I know you don't
want to do, but this is the code I happen to have lying around from
some appdev courseware that I wrote a few years back. It should be
enough to get you started:

private void LoadEmployeePhoto(int employeeID)
{
SqlDataAdapter da = null;
DataTable dt = new DataTable();
string strCnn =
"Data Source=(local);Database=Northwind;"
+ "Integrated Security=SSPI";
string strSQL =
"SELECT Photo FROM dbo.Employees"
+ " WHERE EmployeeID = "
+ employeeID.ToString();
MemoryStream msPic;
// Signature bytes of an
// OLE container header.
const byte OLEbyte0 = 21;
const byte OLEbyte1 = 28;
// Number of bytes in
// an OLE container header.
const int OLEheaderLength = 78;

da = new SqlDataAdapter(strSQL, strCnn);
da.Fill(dt);
if (dt.Rows.Count == 0)
return;

// Move binary picture data into the byte array
byte[] abytPic = (byte[])dt.Rows[0]["Photo"];

// Test for an OLE container header
if ((abytPic[0] == OLEbyte0)
&& (abytPic[1] == OLEbyte1))
{
// Use a second array to strip off the header.
// Make it big enough to hold
// the bytes after the header.
byte[] abytStripped =
new byte[abytPic.Length - OLEheaderLength];
// Strip off the header by copying the bytes
// after the header.
System.Buffer.BlockCopy(
abytPic, OLEheaderLength, abytStripped,
0, abytPic.Length - OLEheaderLength);

// Load the new byte array
// into a MemoryStream.
msPic = new MemoryStream(abytStripped);
}
else
{
// Load the original byte array into a MemoryStream
msPic = new MemoryStream(abytPic);
}
// Set the picture box image, using the stream.
picEmployee.Image = Image.FromStream(msPic);
}

--Mary

On Wed, 5 Oct 2005 20:23:19 +0300, "Alan"
<ne**@stop.spamming.ailon.org> wrote:
Hi,

I'm converting a database application from Access 97 to C#/SQL Server. Old
database contains some images in OLE fields. I've figured out that there's
OLE header preceeding actual image data and dealt with some of the images
which were in standard BMP format but most of the images are in some other
format which is displayed ok in access application and can be copy/pasted to
any image editor but when doubleclicking it doesn't open any application
(like BMP images open Paint, etc.) and I can't figure out how to load it to
.NET image control. The field data for these images starts with some headers
that include two identifiable words "Picture" and "DIB". I've tried
stripping the data in many ways but nothing on my machine is able to open
these.

Does anyone has any experience with this format? Any pointers are greatly
appreciated. Otherwise I'm afraid I'm facing migration of several thousands
of images by copy/pasting from access :/

Thank you in advance,
Alan.

Mar 3 '06 #4

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

Similar topics

0
1100
by: alienize | last post by:
Does anyone know how i would retrieve stored images from my access database(I've stored them as OLE objects) and then bind the retrieved image to an Image Control? Also, How would i retrieve an...
3
2990
by: Dennis | last post by:
How can I save then retrieve an image from an access Database using VB.Net? -- Dennis in Houston
5
1759
by: kbrad | last post by:
I have an Access database set up with a number of text fields and a hyperlink field which references a different image per record. I am trying write ASP code to retrieve allt his data and images...
8
2308
by: Robert | last post by:
I am creating a database that will have a large number of images in it and I would like some input as to the best way to handle them. Each record in my database will have a one-to-many...
9
3813
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
1
1612
by: Bob Allen | last post by:
I am trying to save an image to an access database. I am using the following code as my update syntax. In the example below b is a byte array of the image. All it is putting in the field is Long...
6
3834
by: Bob Alston | last post by:
I am looking for others who have built systems to scan documents, index them and then make them accessible from an Access database. My environment is a nonprofit with about 20-25 case workers who...
1
1374
by: bravephantom | last post by:
how can i save images on my database using ms access? thnx for help
0
7105
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
7144
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
7214
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...
0
5407
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,...
1
4845
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...
0
4529
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...
0
3046
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1359
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
235
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...

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.