文章編號: 894819 - 上次校閱: 2007年11月16日 - 版次: 3.3

如何從一般欄位匯出圖片,藉由使用 ReportListener 基底類別中 Visual FoxPro 9

系統提示本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。

在此頁中

全部展開 | 全部摺疊

結論

本文將告訴您,如何匯出至藉由使用 ReportListener 基底 class.磁碟上的檔案的 Microsoft Visual FoxPro 中欄位的 一般 圖片

簡介

視覺化 FoxPro 一般 欄位經常用來儲存圖片檔案。比方說.jpg 和.bmp 檔案是圖片的檔案。一般 的欄位型別包含不只會儲存該圖片的相關資訊同時也用來寫入圖片至欄位的已註冊伺服器的相關資訊。比方說如果您電腦上的.jpg 檔案的已註冊的伺服器是 Microsoft 相片編輯程式,被串連有關 Microsoft 相片編輯程式] 及 [.jpg 檔案的相關資訊。然後,這項資訊會儲存在 一般 的欄位。

當有 一般 欄位的 Visual FoxPro 資料表移動到另一部電腦時,[] 欄位中影像可能無法正確地顯示因為的額外的伺服器資訊,儲存在欄位中。在表單或報表中,可能就會發生這個問題。甚至當您只是檢視表並修改 一般 的欄位,可能就會發生這個問題。[] 欄位可能不會顯示實際的影像。而是,使用者可能只看到的圖示。

您永遠無法知道有效的伺服器是否出現在電腦上有您的資料表上。因此,可能不想要使用 一般 欄位型別時您的應用程式廣泛使用儲存在資料表中的影像。比方說您可能要在 備忘 (二進位) 欄位中儲存影像。然後,您可以使用 StrToFile 函式來撰寫影像到您需要的磁碟。您也可以使用引進 Visual FoxPro 9 BLOB (二進位大型物件) 欄位型別。或者,您可能會使用 圖像 控制項的 「 PictureVal 」 屬性。

然而,如果您決定要使用不同的方法,您必須使用已經有存放在 一般 的欄位中的圖片。它並不容易從 Visual FoxPro 資料表擷取這些影像,並將它們放到磁碟上。不過,Visual FoxPro 9 在下列程序,可幫助您解決這個問題。

其他相關資訊

本節顯示如何從 員工 範例資料表,也就是隨附於 Visual FoxPro 9 中的 [相片] 欄位中擷取影像的兩個範例。您如此做,請使用新的 ReportListener 基底類別。在 Visual FoxPro 9 開始引進 ReportListener 基底類別。

附註這些範例只會在 Visual FoxPro 9 中運作。

第一個範例示範如何以手動方式建立報表以及然後如何執行報表,以擷取影像。第二個範例示範以程式設計的方法來處理程序。這個第二個範例示範如何建立,以及如何使用程式碼來修改報表。這個第二個範例也示範如何覆寫 RenderAfterBand 事件 XMLListener FoxPro 基礎類別 (FFC) 來微調擷取程序。

附註一般 欄位中的影像顯示的位置正確的電腦上,您必須執行此程序。該影像必須不顯示成圖示。如果您執行此程序在電腦上讓您只看到圖示,將只圖示解壓縮到磁碟。

範例 1: 手動擷取圖片從一般欄位使用 ReportListener 類別

  1. 請確定 Visual FoxPro 設定來執行物件輔助報告。若要執行此動作執行 [在 [命令] 視窗中的 [下列的命令]:
    SET REPORTBEHAVIOR 90
  2. 藉由執行 CREATE 報告 命令在 [命令] 視窗中開啟報表設計工具。
  3. 減少 頁首頁尾 寬線的高度,因此它們 0 英吋高。以本例而言,則不需要這些寬線。
  4. 報表控制項] 工具列新增至詳細資料區段的 [圖片/OLE 繫結 控制項]。再,調整大小 詳細資料 功能的 Band 和 圖片/OLE 繫結 控制項使其大小足以顯示 一般 的欄位中的圖片。
  5. 如果 [圖片/OLE 繫結控制項內容] 對話方塊中不已經開啟、 按兩下 圖片/OLE 繫結] 控制項以開啟它,然後設定下列選項在 [一般] 索引標籤上:
    1. 在 [控制項來源型別,] 下按一下 [一般 (General) 欄位名稱]。
    2. 在 [控制項資料來源] 方塊中,鍵入 [相片]。這是 [員工] 資料表中的 [一般] 欄位名稱。
    3. 按一下以選取 [框架中的水平中心一般欄位] 核取方塊。
  6. 儲存並關閉報表。請注意您用來儲存報表。
  7. 將下列程式碼範例儲存到新的程式,然後再執行它。當會提示您選擇在步驟 6 中儲存的報表。程式碼完成名為相片的 [一般] 欄位中的所有圖片將會都解壓縮至資料夾。此外,解壓縮圖片路徑複製到剪貼簿
    *-----------------------------------
    * Microsoft Knowledge Base Article 894819
    * EXAMPLE 1 
    * AUTHOR: Trevor Hancock
    * CREATED: February 22, 2005 09:59:32
    * ABSTRACT: This code extracts pictures to disk from the 
    *                      General field that is named PHOTO in the 
    *                      EMPLOYEE sample table.
    *-----------------------------------
    CLEAR
    LOCAL lcTestDir AS STRING, ;
    	loListener AS REPORTLISTENER
    
    *-- Create a subfolder of the current
    *-- Visual FoxPro TEMP folder to hold the extracted pictures.
    lcTestDir = ADDBS( SYS( 2023 ) ) + 'GenTst\'
    IF !DIRECTORY( lcTestDir, 1 )
    	MD ( lcTestDir )
    ELSE
    	*-- If DIR is already there, empty it.
    	LOCAL lcOldSetSafe AS STRING
    	lcOldSetSafe = SET( 'Safety' )
    	SET SAFETY OFF
    	ERASE ( lcTestDir + '*.*' )
    	SET SAFETY &lcOldSetSafe
    ENDIF
    
    *-- Open the EMPLOYEE table. The General field that is named
    *-- PHOTO has pictures in it.
    USE ADDBS( HOME() ) + 'Samples\Data\Employee.dbf'
    
    *-- Here we run the Report Output Application (ReportOutput.app) in HOME().
    *-- We pass it a 5. This means that we want the Report Output Application
    *-- to store an object reference to an HTMLListener-type
    *-- ReportListener base class to the second parameter that we pass: loListener.
    DO HOME() + 'ReportOutput.app' WITH 5, loListener
    
    *-- Tell the HTMLListener to save the output (the .HTM page)
    *-- to a specific folder. This folder is the one created earlier.
    loListener.TargetFileName = lcTestDir + 'tmp.htm'
    *-- Typically, a report that is run by using an HTMLListener
    *-- displays wait windows during processing and a
    *-- message box at the end. We want to turn this off. Therefore,
    *-- we set QuietMode = .T.
    *-- Note: This also turns off error reports from the ReportListener.
    loListener.QUIETMODE = .T.
    
    *-- Run the report by using the Listener.
    REPORT FORM GETFILE('FRX') OBJECT loListener
    *-- This command deletes the .html file that is produced.
    *-- We do not need it.
    ERASE ( loListener.TargetFileName )
    
    *-- Clean up, and then report that the process has finished.
    *-- To see the results, use Microsoft Windows Explorer to
    *-- view the folder path that is stored in the Windows Clipboard.
    CLOSE DATA ALL
    _CLIPTEXT = lcTestDir
    ? 'Pictures have been extracted to ', lcTestDir
    ? 'This path is in your Clipboard.'
    

範例 2: 以程式設計方式擷取圖片從一般欄位使用 ReportListener 類別

儲存到新的.prg 檔案這個程式碼範例。然後,執行程式會自動建立報表,並使用報表來從 員工 資料表擷取的相片。

附註不論是在名為 TmpTst C 磁碟機上建立一個資料夾,或重新定義 lcTargetDir 變數,以指向您所選擇的資料夾。
*-----------------------------------
* Microsoft Knowledge Base Article 894819
* EXAMPLE 2
* AUTHOR: Trevor Hancock
* CREATED: February 22, 2005 09:59:32
* ABSTRACT: This code extracts pictures to disk from the 
*                 General field that is named PHOTO in the 
*                 EMPLOYEE sample table.
*-----------------------------------

*-- This opposite value of the constant will be used to set the QuietMode
*-- property of the ReportListener base class. When the value is .T., 
*-- wait windows that indicate processing appear. At the end, a message box
*-- appears. Any errors in the ReportListener base class also appear.
#DEFINE ShowReportFlow_Errs  .F.

LOCAL lcReportName AS STRING, ;
	lcGenFldName AS STRING, ;
	lnGenFldHeight AS INTEGER, ;
	lnGenFldWidth AS INTEGER, ;
	lcTargetDir AS STRING, ;
	lcFileNameExpr AS STRING, ;
	lcGenTable AS STRING

*-- Choose the name of a table to extract one General
*-- field from.
lcGenTable = ADDBS( HOME() ) + 'Samples\Data\employee.dbf'

*-- Set the name of the General field that you want to extract from.
lcGenFldName = 'PHOTO'

*-- Set the height that you want for the General field.
lnGenFldHeight = 8000.00

*-- Set the width that you want for the General field.
lnGenFldWidth = 7000.00

*-- Set the folder into which the General field
*-- pictures will be extracted.
lcTargetDir = 'C:\TmpTst\'

*-- By default, pictures that are rendered to disk by the ReportListener class
*-- use the following file name format: _n.jpg. In this format, n
*-- is a number. If you set this next variable to an expression, you 
*-- can override that behavior. In this example, we name
*-- the .jpg files based on the FIRST_NAME and LAST_NAME
*-- fields from the EMPLOYEE table that we are reporting from.

*-- This expression will be wrapped in the EVAL function when it is called. 
*-- Therefore, make sure that you specify an expression, a variable, or something else. 
*-- Possible choices include the RECNO function and other table field names.
lcFileNameExpr = ;
	"ALLT(Employee.First_Name) + '_' + ALLTRIM(Employee.Last_Name)"



*------ START REPORT CREATION
*
CLOSE DATA ALL
IF !DIRECTORY( lcTargetDir, 1 )
	MESSAGEBOX( 'Target output folder does not exist. Process stopped.', 48, '' )
	RETURN .F.
ENDIF
CD ( lcTargetDir )

*-- Clean up the folder first to prevent any file name conflicts.
LOCAL lcOldSetSafe as String
lcOldSetSafe = SET("Safety")
SET SAFETY OFF
DELETE FILE *.*
SET SAFETY &lcOldSetSafe

*-- Create a temporary cursor to base the report
*-- on, make the report, and then close the cursor.
*-- This temporary cursor is used to set up the report for the first time.
*-- It is not needed after the report is made.
lcReportName = lcTargetDir + 'GenReport'
CREATE CURSOR TEMP ( Fld1 G )
CREATE REPORT ( lcReportName ) FROM TEMP
USE IN TEMP

*-- Open the report file (FRX) as a table.
USE ( FORCEEXT( lcReportName, 'FRX' ) ) IN 0 ALIAS TheReport EXCLUSIVE
SELECT TheReport

*-- This command removes objects that are not required 
*-- from the report surface and from the report table itself.
*-- ObjType = 5 or 8: Removes the label and field objects from the footer.
*-- ObjType = 23 & FontStyle = 1: Removes a font resource
*-- that is not needed. The resource belonged to the label that was deleted.
DELETE ALL FOR (ObjType = 23 AND FontStyle = 1) ;
	OR INLIST(ObjType, 5, 8) IN TheReport

*-- This command adjusts the layout of the header and footer bands.
*-- ObjType = 9 & ObjCode = 1 means Page Header band.
*-- ObjType = 9 & ObjCode = 7 means Page Footer band.
*-  Reduce them because they are not required for this code.
UPDATE TheReport SET Vpos = 0, Hpos = 0, HEIGHT = 0 ;
	WHERE ObjType = 9 AND (ObjCode = 1 OR ObjCode = 7)

*-- Increase the height of the Detail band
*-- (ObjType = 9 & ObjCode = 4) to fit the
*-- Picture/OLE Bound control that is inserted by using the next command.
UPDATE TheReport SET Vpos = 0, Hpos = 0, HEIGHT = lnGenFldHeight ;
	WHERE ObjType = 9 AND ObjCode = 4

*-- Add a Picture/OLE Bound control to the report by inserting a
*-- record with appropriate values. Using an object that is based on the EMPTY
*-- class here and the GATHER NAME class later to insert the record makes it easier to
*-- see which values line up to which fields when compared to a large
*-- SQL-INSERT command).
LOCAL loNewRecObj AS EMPTY
loNewRecObj = NEWOBJECT('EMPTY')
ADDPROPERTY( loNewRecObj, 'PLATFORM', 'WINDOWS' )
ADDPROPERTY( loNewRecObj, 'Uniqueid', SYS(2015) )
ADDPROPERTY( loNewRecObj, 'ObjType', 17 ) && "Picture/OLE Bound control"
ADDPROPERTY( loNewRecObj, 'NAME', lcGenFldName ) && Name of the General field in the cursor.
ADDPROPERTY( loNewRecObj, 'Vpos', 2083.333) && Put it in the Detail band.
ADDPROPERTY( loNewRecObj, 'HEIGHT', lnGenFldHeight )
ADDPROPERTY( loNewRecObj, 'WIDTH', lnGenFldWidth )
ADDPROPERTY( loNewRecObj, 'DOUBLE', .T. ) && The picture is centered in the Picture/OLE Bound control
ADDPROPERTY( loNewRecObj, 'Supalways', .T. )
*-- For the Picture/OLE Bound control, the contents of the OFFSET field specify whether
*-- File name (0), General field name (1), or Expression (2) is the source.
ADDPROPERTY( loNewRecObj, 'Offset', 1 )

*-- Add the Picture/OLE Bound control record to the report.
APPEND BLANK IN TheReport
GATHER NAME loNewRecObj MEMO

*-- Clean up and then close the report table.
PACK MEMO
USE
*
*------ END REPORT CREATION


*-- Rerun the report by using the Listener subclass
*-- that is defined in later code.
USE ( lcGenTable )
LOCAL loXMLD_Listener AS ;
	XMLDISPLAYLISTENER OF ADDBS( HOME( ) ) + 'Ffc\_reportlistener.vcx'

loXMLD_Listener = NEWOBJECT( 'MyListener' )
loXMLD_Listener.TargetFileName = ADDBS( lcTargetDir ) + 'tmp.htm'
loXMLD_Listener.ImgFileNameExpr = lcFileNameExpr
loXMLD_Listener.QUIETMODE = !ShowReportFlow_Errs

WAIT WINDOW 'Rendering pictures.' NOWAIT NOCLEAR
REPORT FORM ( lcReportName ) OBJECT loXMLD_Listener
ERASE (loXMLD_Listener.TargetFileName)
ERASE ( FORCEEXT( lcReportName , '*' ) )
RELEASE loXMLD_Listener
WAIT WINDOW 'Complete!' TIMEOUT 2
RETURN



*----------------------------------
*----------------------------------
DEFINE CLASS MyListener AS XMLDISPLAYLISTENER OF ADDBS(HOME()) + 'Ffc\_reportlistener.vcx'
	ImgFileNameExpr = ''
	ImgFile = ''

	PROCEDURE RENDER(nFRXRecNo, nLeft, nTop, nWidth, nHeight, ;
			nObjectContinuationType, cContentsToBeRendered, GDIPlusImage)
		NODEFAULT

		*-- ImageFileBaseName is an optional prefix to be added
		*-- to generated image file names when image files are saved
		*-- to disk during the rendering of general fields in a report run.
		THIS.ImageFileBaseName = EVAL( THIS.ImgFileNameExpr )

		*-- This is the full path and file name of the picture file that will
		*-- be rendered to disk when the DODEFAULT function is called. This information is retrieved here
		*-- so we can clean it up in the AfterBand event.
		THIS.ImgFile	 = FORCEPATH(THIS.ImageFileBaseName + "_" + ;
			TRANSFORM(THIS.ImageFieldInstance + 1) + ".jpg", ;
			FULLPATH(THIS.ExternalFileLocation,ADDBS(JUSTPATH(THIS.TargetFileName))))

		DODEFAULT(nFRXRecNo,nLeft,nTop,nWidth,nHeight, ;
			nObjectContinuationType, cContentsToBeRendered, GDIPlusImage)
	ENDPROC


	PROCEDURE AFTERBAND(nBandObjCode, nFRXRecNo)
		NODEFAULT

		IF nBandObjCode = 4 && In Detail Band
			*-- Look for the image file on the disk.
			*-- If the image file is there, the code inside the IF...ENDIF
			*-- construct strips off the _n that is at the end of the file name,
			*-- just before the extension. This is added in the Render event by the
			*-- XMLDISPLAYLISTENER class. You do not have to clean up the file name.  However,
			*-- it looks cleaner. For example, "Scott_Rockfeld_1.jpg" would change to
			*-- "Scott_Rockfeld.jpg".
			IF FILE( THIS.ImgFile )
				LOCAL lnLastUnderscorePos AS INTEGER
				lnLastUnderscorePos = ATC('_', THIS.ImgFile, OCCURS( '_', THIS.ImgFile ) )
				RENAME ( THIS.ImgFile ) TO ;
					FORCEEXT( SUBSTR( THIS.ImgFile, 1, lnLastUnderscorePos - 1 ), 'JPG' )
			ENDIF
		ENDIF

		DODEFAULT( nBandObjCode, nFRXRecNo )
	ENDPROC
ENDDEFINE
如需有關匯出內嵌點陣圖影像,請按一下下面的文件編號,檢視 「 Microsoft 知識庫 」 中的發行項件:
161832? (http://support.microsoft.com/kb/161832/ ) 如何匯出到檔案中內嵌的.bmp 影像
取得更多資訊有關 FRX 資料表結構請參閱 Visual FoxPro 說明中"表格檔案 (.dbc、.frx、.lbx、.mnx、.pjx、.scx、.vcx) 的資料表結構 」 主題]。

若要直接檢閱 Visual FoxPro 9.0 FRX 資料表結構,請在 [命令] 視窗中執行下列命令:
報告 FORM HOME() + \Tools\Filespec\90frx.frx 預覽

?考

如需有關 ReportListener XML 顯示樣式的基礎類別的詳細資訊,請造訪下列 Microsoft 開發 o 人 h 員 ? 工 u 具 ? 網路 (MSDN) 網站]:
http://msdn2.microsoft.com/en-us/library/ms995317(VS.80).aspx (http://msdn2.microsoft.com/en-us/library/ms995317(VS.80).aspx)

這篇文章中的資訊適用於:
  • Microsoft Visual FoxPro 9.0 Professional Edition
關鍵字:?
kbmt kbcodesnippet kbhowto KB894819 KbMtzh
機器翻譯機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:894819? (http://support.microsoft.com/kb/894819/en-us/ )
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。