I\'m working on redeveloping an Access based system into c#.net, however when MS went from office 2003 to office 2007 they removed the picture editor within access - which m
Try this KB http://support.microsoft.com/kb/317701 article from microsoft. It contains information on how to access the image blob from access and display that in winforms application.
In my case the following function worked. The data are stored by a VB6 application.
public static byte[] ConvertOleBytesToRawBytes(byte[] oleBytes)
{
// The default encoding is in my case - Western European (Windows), Code Page 1252
return Encoding.Convert(Encoding.Unicode, Encoding.Default, (byte[])oleBytes);
}
Trying to retrieve an MS-access OLE image field from .NET is way more headache than it is worth. There is some good discussion and info about this topic in this post.
Ultimately, your best, and easiest, solution to be successful with this is to use your working viewing method to save these images as separate files, then import those files into the database as BLOB fields, rather than image fields. Then you can easily read them into .NET.
It is not C# code but here is an Delphi example of a way to solve this problem.
It uses the IOLEObject to draw whatever is stored instead of trying to read out the raw data. Steps:
I needed to do the exact same thing for some 1600 object of different extension types. In my case it was a legacy database that had literally been used for decades. Over the years many different types of files had been added via an OLE Object frame. Some of the items that looked like "Images" turned out to be Word documents with an embedded image... no telling what other file types were in there? All I know is that I researched and tried different extraction methods for more than a week. Even all of Steven Leban's extraction tools like OLEtoDisk, A2KExportOLEtoJPEG, and SaveOLEtoBitmap. Each of which would extract some images... but their was no one size fits all... it was a mess!
In the end I ended up performing an automated screen shot of each image via VBA using the method below. While this may not have been the most ideal it worked for every file type. However the screen shot method captures a screen shot of the full screen. Once I had all of them extracted I then had to use PhotoShop to do another automated process to batch crop all of the photos. Not ideal but it worked!
Private Sub CaptureAllImages()
On Error Resume Next
Me.RecordsetClone.MoveFirst
Do While Not Me.RecordsetClone.EOF
Me.Bookmark = Me.RecordsetClone.Bookmark
Call Pause(2)
Call SaveClip2Bit("C:\Users\agriggs\Desktop\Parts Images\MasterPart_" & Me.MasterPartNumber & ".bmp")
Me.RecordsetClone.MoveNext
Loop
End Sub
Public Function Pause(NumberOfSeconds As Variant)
On Error GoTo Error_GoTo
Dim PauseTime As Variant
Dim start As Variant
Dim Elapsed As Variant
PauseTime = NumberOfSeconds
start = Timer
Elapsed = 0
Do While Timer < start + PauseTime
Elapsed = Elapsed + 1
If Timer = 0 Then
' Crossing midnight
PauseTime = PauseTime - Elapsed
start = 0
Elapsed = 0
End If
DoEvents
Loop
Exit_GoTo:
On Error GoTo 0
Exit Function
Error_GoTo:
Debug.Print Err.Number, Err.Description, Erl
GoTo Exit_GoTo
End Function
I tried a couple different screen shot modules but found that the SaveClip2Bit worked the best. Lastly I added a common Pause function to insure the image got saved to disk before moving on to the next. As you can imagine 1600 images took a long time to extract but I can now but this project to rest!