473,516 Members | 3,355 Online
Bytes | Software Development & Data Engineering Community
+ 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 7446
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 image from a specific row using the SelectedIndexChanged event?...I'm thinking that i need to use some sort of array. Thanks in advance, Alex
3
2993
by: Dennis | last post by:
How can I save then retrieve an image from an access Database using VB.Net? -- Dennis in Houston
5
1762
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 onto a web page. I have the data but the images are causing a problem. The code I am using is as follows: For the data: <TD><P><FONT...
8
2315
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 relationship with a Pictures table, i.e. there will be several pictures for each record in my main table. There are several things that I would like to be...
9
3816
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 site for a small club I belong to and one of the features I would like to include is the ability to allow users to upload image files. ...
1
1617
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 Binary Data. UPDATE datapath SET img_fnt = '" + b + "' where path1 = 'xxx'; the column is created as an ole object. any help is appreicated. ...
6
3840
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 use laptops. They have Access databases on their laptops and the data is replicated. The idea is that each case worker would scan their own...
1
1375
by: bravephantom | last post by:
how can i save images on my database using ms access? thnx for help
0
7273
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7574
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...
1
7136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7547
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...
0
5712
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...
0
3265
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3252
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1620
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 we have to send another system
1
823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.