0

我正在 VB6 中编写代码来保存和检索 .dbf 文件中的图像,但我不知道在 dbf 文件中采用什么字段类型。谁能建议我应该在 dbf 文件中使用什么字段以及我应该在 VB6 中编写什么代码?提前致谢..

4

3 回答 3

1

我很久以前在备忘录字段中做过。代码在foxpro中。看:

CREATE TABLE Abc.dbf Free (Filename c(50), Store M(4)) &&Create a table with FileName character field

*并存储为备忘录字段

1.

Append blank &&to add a blank record
APPEND MEMO store from "D:\Shah.Jpg" overwrite 
*This will copy the contents of the file. If Overwrite is ignored, and the memo has some contents,
*The contents of the file will be appended to it, which should be avoided.
REPLACE filename WITH "Shah.Jpg"
*Add as many files as you wish to other records.
Copy memo Store to "SomePhoto.jpg" && will copy to the default folder
*Or 
Copy memo store to "c:\MyPhotos\Shah.JPG" &&You must save or know the extension of the file

2.

append blank
filedata=FILETOSTR("D:\Shah.JPG")
REPLACE store WITH filedata
STRTOFILE(store,"SomeFileName.JPG")
*OR
STRTOFILE(store,"c:\MyPhotos\SomeFileName.JPG")

它应该可以解决您的问题。

于 2012-11-15T18:09:09.563 回答
1

我很久以前在备忘录字段中做过。代码在foxpro中。看:

CREATE TABLE Abc.dbf Free (Filename c(50), Store M(4)) 

*创建一个带有文件名字符字段的表

*并存储为备注字段方法1:

追加空白 && 以添加空白记录

APPEND MEMO store from "D:\Shah.Jpg" overwrite 

*这将复制文件的内容。如果 Overwrite 被忽略,并且备忘录有一些内容,*文件的内容将被附加到它上面,应该避免这种情况。

REPLACE filename WITH "Shah.Jpg" 

*将任意数量的文件添加到其他记录中。

Copy memo Store to "SomePhoto.jpg" 
  • 将复制到默认文件夹或

    Copy memo store to "c:\MyPhotos\Shah.JPG"

*您必须保存或知道文件的扩展名

方法2。

追加空白

filedata=FILETOSTR("D:\Shah.JPG") 

REPLACE store WITH filedata 

STRTOFILE(store,"SomeFileName.JPG") 

*或者

STRTOFILE(store,"c:\MyPhotos\SomeFileName.JPG")

***它应该可以解决您的问题。

于 2012-11-15T18:14:04.497 回答
0

这就是我在 Fox pro 9 中的做法,它涉及从 MYSQL 服务器保存和检索图像。1.首先按名称创建表:图片有两个字段image_id(int 10)和image(longBlob)。

现在我写了两个函数 SaveImage RetriveImage"

CLOSE DATABASES

DO SaveImage WITH "C:\Users\Admin\Desktop\New folder (6)\rafay.jpg"
DO RetriveImage WITH "C:\KalimKhan2.jpg"



Function SaveImage
    Parameters ImageName

   && Get image info
   Create Cursor im (pic Blob)
   Appen Blank

  Overwrite`enter code here`
  Append Memo pic From (ImageName) Overwrite

  SQLDisconnect(0)
  nconnect = SQLConnect('TEST_BOX','root')
   If nconnect < 0
       Wait Window 'Connection Failed!' Timeout 1
       Return
   Else
      Wait Window 'Connected. ' Nowait
  Endif
  nresult = SQLExec(nconnect, [INSERT INTO pictures (image) VALUES (?pic) ] )

  If nresult != 1
      Aerror(laErr)
      List Memory Like laErr To File c:\Error
      error1 = .T.
      =Aerror(x)
      Wait Window " Query failed."
  Endif


Return  "good"



Function RetriveImage
    Parameters ImageName

   SQLDisconnect(0)
   nconnect = SQLConnect('TEST_BOX','root')
   If nconnect < 0
       Wait Window 'Connection Failed!' Timeout 1
       Return
   Else
       Wait Window 'Connected. ' Nowait
   Endif

   CursorSetProp("MapBinary",.T.,0)
   nresult = SQLExec(nconnect, [Select * from pictures where image_id = 1 ],"ImageTemp" )
   If nresult != 1
       Aerror(laErr)
       List Memory Like laErr To File c:\Error
       error1 = .T.
       =Aerror(x)
       Wait Window " Query failed."
    Endif

nBytes = Strtofile (ImageTemp.Image, (ImageName))
于 2016-10-07T12:59:41.060 回答