Read the graphics field of the Access database

zhaozj2021-02-08  191

Read the graphics field of the Access database

(Using Delphi 5 AdoExpress)

Information is provided, organized: Chen Guosheng, Cai Huanlin, Zhu Zi

Summary

"How to read and display the graphics field information of the Access database?" It is already a FAQ, which is the method of solving this problem. This method was originally available in an article in the EFG's Computer Lab website, but this article has already disappeared on the website. If you search for the Borland news group, you can find a similar answer, and organize this article is just convenient for you.

Please make sure your computer has Microsoft installed in Microsoft. In this article, we will use it to be included in the North Air Database.

Reproduction

Create a new project, then place an Adodataset, Datasource, Dbimage, DBGrid on Form1. Set the connectionString property of AdodataSet1:

Provider = microsoft.jet.OLEDb.4.0; data source = c: / proGram files / microsoft office / office / samples / northwind.mdb; persist security info = false and CommandText properties:

SELECT * FROM product category After setting the properties of each component, set the ADODATATISET1's Active property to True, and an error message "Bitmap Image is not valid." Since the graphic is in the form of an OLE article, DBIMAGE does not support this format graphical data, thereby incorrectly. You can add the following trip code in the program, which will save graphics to the blob.dat file: tblobfield (adodataset1.fieldbyname ('picture')). Savetofile ('blob.dat'); if you use UltraEdit The tool of the class examine the content of the file, you can see it probably growing this:

1 151C2F00020000000D000E0014002100 .. / ...........!

2 ffffffffff4269746d617020496d616765 .... Bitmap Image

.Paint.Picture.................................

4 05000002000000070000005042727573 ........... PBRUS

5 68000000000000000000000020540000424D H ......... t.

6 165400000000000000760000002800000000.T ... V ... (...

7 C0000000DF000000010004000000000000 ..............

8 A0530000 CE0E0000D80E000000000000.S ............

9 0000000000000000000000800000800000 ..............

10 0080800080000000800080008080800000 ................

11 C0C0C000808080000000FF0000FF0000 ..............

1200ffff00ff000000FF00FF00FFFF0000 ................

13 fffffff00ff0cb0c9000b090900000a00 ................ 14 9009000000000909A09A900B09000A90 ................

15 A00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCB ..............

16 9cfcfefffffffffffedffffedeffdeFefc ..............

17 fffdada00d900009009009000000000 ................

18 090A00090BC0000900900000000A00AC ..............

19 A0E0E0E0F0E9CA9000A9CB0C00009090 ................

20 E0000009090B0000D009009000000900 ................

21 009A000ffffffffffffffeffffffffffffcad ................

22 EBDBDFDFFFFFFFFFFEFFEDFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ..............

23 Fefcaf0c9a0a0d00009a00000000000000 ..............

24 00090A000B009A9000090000900C09 ..............

25 00900900FA90ADA00090B00B00000000 ................

...

Solution

As mentioned earlier, DBIMAGE does not display graphic, because the graphical data of this field is stored in the format of the OLE object (whether it doesn't matter if the Access database is not related), so the solution is to put the OLE format graphics data. Convert Bitmap format for Dbimage, refer to the following steps:

Delete dbimage1 and paste the following code to your program:

Procedure LoadimageFromfield (Afield: tblobfield);

VAR

ABITMAP: TBITMAP;

ASTREAM: TMEMORYSTREAM;

Begin

IF Afield.isnull Then

EXIT;

ASTREAM: = TMEMORYSTREAM.CREATE;

Try

Afield.saveTostream (astream);

// Skip Ole Storage HEADER

Astream.seek (78, SOFROMBEGINNIN);

Abitmap: = tbitmap.create;

Try

Abitmap.LoadFromstream (astream);

APICTURE.GRAPHIC: = ABITMAP;

Finally

Abitmap.free;

END;

Finally

ASTREAM.FREE;

END;

End; call loadImageFromfield in AdodataSet1:

Procedure TFORM1.ADOTABLE1AFTERSCROLL (DataSet: TDataSet);

Begin

Loadimagefromfield

Image1.picture,

Dataset.fieldbyName ('Picture') as Tblobfield

);

END;

Compile and execute, now you should see that the graphics field is correctly displayed in Image1.

Download FangDex: AdoaccessImg.zip

additional materials

[Employee] The [Photo] field of the information sheet (Zhu Zi) is a netizen (BCC10212001) written the following problems in the "Point Space" message board:

Ask a question ....

In the Delphi unit I can see that the graphics field is displayed correctly in Image1. If Table is changed to "employee", it will not, the problem of Bitmap is not valid, what is going on ...

Today, I will organize my reply here, share with you:

If you use the Access 2002 version, the information format of the employee photo field has been changed to "text" format, so this method can not be used.

However, you use Access 2000 or previous version, first, I must point out that Microsoft builds employees, it is established in Access 97 or earlier Access 2.0, and these materials are not converted or change. Therefore, although it is also the data format of the OLE object, the stored form is different. When I transfer the "product category" "picture" field, after transferring the "employee" "photo" field data, it can be found together, I can find these micro-different, I will list the information. as follows:

"Picture" section of "Product Category"

-------------------------------------------------- ------------------

1: 15 1C 2F 00 02 00 00 0d 00 0E 00 14 00 21 00; .. / ...........!

2: FF FF FF 42 69 74 6D 61 70 20 49 6D 61 67 65; .... Bitmap Image

3: 00 50 61 69 6e 74 2E 50 69 63 74 75 72 65 00 01; .paint.picture ..

4: 05 00 00 02 00 00 00 00 00 00 00 42 72 75 73; ......... PBRUS

5: 68 00 00 00 00 00 00 00 00 00 00 42 4d; H ......... t.com

6: 16 54 00 00 00 00 00 76 00 00 00 00 00; .t ... V ... (...

7: c0 00 00 00 00 00 00 01 00 04 00 00 00 00; ..............

-------------------------------------------------- ------------------

"SEC" "Photo" field information

-------------------------------------------------- ------------------

1: 15 1C 2D 00 02 00 00 0B 00 0E 00 14 00 1f 00; ..-...........

2: FF FF FF FF C2 49 B0 7D B9 CF BC 76 B9 B3 00 50; Dot matrix image .P

3: 61 69 6e 74 2E 50 69 63 74 75 72 65 00 01 05 00; AINT.PICTURE ....

4: 00 02 00 00 00 00 00 00 00 42 72 75 73 68 00; ......... PBRUSH.

5: 00 00 00 00 00 00 聽 53 00 00 42 4d B6 53; ........ ..bm 腼 腼

6: 00 00 00 00 00 00 76 00 00 00 28 00 00 00 C0 00; ...... v ... (... 7: 00 00 DE 00 00 00 01 00 04 00 00 00 00 00? 40 53; ..? .......... @ s

-------------------------------------------------- ------------------

Please pay attention to [42 4D B6 53] (Fifth line), in the "picture" field of "product category", from the headed to 79 sites, and in "Operators" field data But appeared at the 77th place. Therefore, it can be apparent from the data from both parties that the difference between the two characters, and this is the key to the "Bitmap IS Not Valid" error message when accessing the employee photo information. Therefore, in the "photo" field of "employee", the previously written loadIMFROMFIELD function must be modified:

Original:

Astream.seek (78, SOFROMBEGINNIN);

Change to:

Astream.seek (76, SOFROMBEGINNIN);

~ End ~

NOV-13-2001, APR-13-2002

转载请注明原文地址:https://www.9cbs.com/read-3140.html

New Post(0)