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

如何列印圖片,以及如何來顯示儲存在中 Visual FoxPro 9.0 BLOB (二進位大型物件) 欄位中的圖片

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

在此頁中

全部展開 | 全部摺疊

結論

Microsoft Visual FoxPro 9.0 介紹 BLOB (二進位大型物件) 資料型別。您可以使用 BLOB (二進位大型物件) 的欄位來儲存二進位資料,例如圖片。會儲存在 BLOB (二進位大型物件) 欄位中的圖片可以列印在報表上,並顯示在表單上。本文說明如何列印圖片] 及顯示圖片會儲存於 一個 BLOB (二進位大型物件) 欄位。

簡介

視覺化 FoxPro 9.0 介紹 BLOB (二進位大型物件) 資料型別。您可以使用 BLOB (二進位大型物件) 的欄位來儲存任何種類的且不定的長度的二進位資料。比方說您可以將圖片儲存在 BLOB (二進位大型物件) 欄位。

您可以列印會儲存在報表上的 BLOB (二進位大型物件) 欄位中使用 圖片/OLE 繫結 控制項的圖片。若要列印儲存在 BLOB (二進位大型物件) 欄位中的圖片,您必須將 圖片/OLE 繫結 控制項所使用的控制項資料來源設定為物件參考。圖像 控制項的執行個體必須是物件參考。這個執行個體的 [PictureVal 屬性必須設定為包含圖片的 BLOB (二進位大型物件) 欄位。

您可以顯示會儲存在表單上的 BLOB (二進位大型物件) 欄位中使用 圖像 控制項的圖片。您直接在表單上放置 影像 控制項,而且您設定 圖像 控制項的 「 PictureVal 」 屬性。此位址結合 圖像 控制項至 BLOB (二進位大型物件) 欄位。但是,額外的步驟是必要強制 Image 控制項重繪當記錄指標移動的資料表包含 BLOB (二進位大型物件) 功能變數。

其他相關資訊

下列程式碼範例則被為了 Visual FoxPro 9.0。這些程式碼範例顯示如何列印圖片] 和 [如何顯示會儲存為二進位資料 BLOB (二進位大型物件) 欄位中的圖片。 若要測試這些範例,請依照下列步驟執行:
  1. 啟動 Visual 的 FoxPro 9.0 並建立兩個新的程式。
  2. 複製,然後將範例 1 貼到其中一個新的程式。
  3. 複製,然後將範例 2 貼到另一個新程式。
  4. 儲存並執行程式。

會儲存在報表上的 BLOB (二進位大型物件) 欄位中的範例 1: 列印圖片

下列程式碼範例會示範如何列印圖片儲存為報表上的 BLOB (二進位大型物件) 欄位中的二進位資料。
*------------ START CODE
*
*-----------------------------------
* AUTHOR:    Trevor Hancock
* CREATED:   03/04/05 01:03:07 P.M.
* ABSTRACT: Code from Microsoft Knowledge Base
*                 article 895602. Visual FoxPro code that shows how
*                 to use pictures that are
*                 stored in a BLOB field in a report.
*                 This is accomplished by using an
*                 object reference to an instance of
*                 an IMAGE class as the control source for
*                 an OLE Bound control on the report. The IMAGE
*                 object has its PictureVal property set to a BLOB
*                 field in a cursor.
*-----------------------------------
LOCAL lcDataDIR AS STRING, ;
	lcThisDir AS STRING, ;
	loRL AS REPORTLISTENER

lcDataDIR = HOME( ) + 'Samples\Tastrade\'
lcThisDir = ADDBS( JUSTPATH( SYS( 16 ) ) )

CD ( lcThisDir )
CLOSE DATA ALL
*-- Create a temp cursor with a few fields, one of which is a
*-- BLOB. Store pictures in this field as raw binary data.
SELECT CAST( ALLTRIM( First_Name ) AS VARCHAR ( 10 ) ) AS 'FNAME', ;
	CAST( ALLTRIM( Last_Name ) AS VARCHAR (10 ) ) AS 'LNAME', ;
	CAST( FILETOSTR( lcDataDIR + Photo_File ) AS BLOB ) AS 'PIC' ;
	FROM ( lcDataDIR + 'data\Employee.dbf' ) ;
	INTO CURSOR ReportTemp

*-- Close the table that you selected from. It is not needed.
USE IN SELECT( 'EMPLOYEE' )

*-- This calls a function that makes a report programmatically.
*-- This is included here just to make sure that this sample can be run
*-- as-is, without asking the developer to manually create a report.
MakeReport()

*-- Create an instance of the PreviewListener
*-- class defined later in this code.
*-- Call its custom InitBLOBImage() method,
*-- which creates an instance of an IMAGE object.
*-- This IMAGE has its PictureVal property set to the BLOB
*-- field ( 'ReportTemp.PIC' ) and its reference ( loRL.oBlobImage )
*-- is used as the control source for the OLE Bound control 
*-- on the report.
loRL = NEWOBJECT( 'PreviewListener' )
loRL.InitBLOBImage( 'ReportTemp.PIC' )

*-- Make sure that the cursor is selected,
*-- and then run the report to preview using
*-- the instance of our Report Listener.
SELECT ReportTemp
REPORT FORM BlobReport OBJECT loRL
CLOSE DATA ALL
RETURN





*--------------------------------
*-- There has to be some way of redrawing the
*-- picture in the IMAGE class as the record pointer
*-- in the report's driving cursor changes; it does not occur
*-- automatically. This could be done by a UDF() in the PrintWhen
*-- of the OLE Bound control on the report, or as is illustrated here,
*-- by a Report Listener BEFOREBAND() Event.
DEFINE CLASS PreviewListener AS REPORTLISTENER
	oBlobImage = NULL
	PicBlobFld = ''
	LISTENERTYPE = 1  && Preview Listener

	PROCEDURE InitBLOBImage(lpcBlobField AS STRING)
		THIS.PicBlobFld = lpcBlobField
		THIS.oBlobImage = NEWOBJECT( 'IMAGE' )
		THIS.oBlobImage.PICTUREVAL = THIS.PicBlobFld
	ENDPROC

	PROCEDURE BEFOREBAND( nBandObjCode, nFRXRecNo )
		*-- Before the DETAIL band is rendered, ;
		*-- just redraw the IMAGE object so that it has
		*-- the correct picture from the BLOB field.
		IF nBandObjCode = 4 && Detail band
			THIS.oBlobImage.PICTUREVAL =;
				EVALUATE( THIS.PicBlobFld )
		ENDIF
	ENDPROC
ENDDEFINE




*--------------------------------
*-- This function programmatically creates a report
*-- with an OLE Bound control and other fields. This is included
*-- only for demonstration purposes so this article code can stand-alone.
*-- Typically, you would create your own report manually by using
*-- the report designer.
FUNCTION MakeReport
	CREATE REPORT BlobReport FROM ReportTemp

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

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

	*-- Since you increased the height of the Detail Band, you need to move
	*-- the items from the footer down so they are back in the footer again.
	UPDATE TheReport SET Vpos = 29479.167 ;
		WHERE ( ObjType = 8 OR ObjType = 5 ) AND ;
		INLIST( EXPR, 'DATE()', '"Page "', '_PAGENO' )

	*-- 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', 'loRL.oBlobImage' ) && The object ref to the IMAGE object.
	ADDPROPERTY( loNewRecObj, 'Hpos', 27500.000) && Place it in DETAIL band.
	ADDPROPERTY( loNewRecObj, 'Vpos', 3854.167)
	ADDPROPERTY( loNewRecObj, 'HEIGHT', 21354.167)
	ADDPROPERTY( loNewRecObj, 'WIDTH', 25104.167)
	ADDPROPERTY( loNewRecObj, 'DOUBLE', .T. ) && 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
	*-- Filename (0), General field name (1), or Expression (2) is the source.
	ADDPROPERTY( loNewRecObj, 'Offset', 2 )

	*-- 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 IN SELECT( 'TheReport' )
ENDFUNC
*
*------------ END CODE

範例 2: 顯示儲存在表單上的 BLOB (二進位大型物件) 欄位中的圖片

下列程式碼範例會示範如何顯示圖片儲存為表單上的 BLOB (二進位大型物件) 欄位中的二進位資料。
*------------ START CODE
*
*-----------------------------------
* AUTHOR:    Trevor Hancock
* CREATED:   03/04/05 01:03:07 P.M.
* ABSTRACT: Code from Microsoft Knowledge Base
*                 article 895602. Visual FoxPro code that shows how
*                 to display pictures that are
*                 stored in a BLOB field on a form.
*-----------------------------------
CLOSE DATA ALL

*-- Create a temp cursor with a BLOB field.
*-- Store pictures in this field as raw binary data.
SELECT 	;
	CAST( ;
	FILETOSTR( HOME( ) + 'Samples\Tastrade\' + Photo_File ) ;
	AS BLOB ) AS 'PIC' FROM ;
	HOME( ) + 'Samples\Tastrade\data\Employee.dbf' ;
	INTO CURSOR BlobTemp

*-- Close the table that you selected from. It is not needed.
USE IN SELECT( 'EMPLOYEE' )

*-- Create a form to display the pictures.
PUBLIC goForm
goForm = NEWOBJECT( 'Form' )

WITH goForm AS FORM
	*-- Add an IMAGE class to display the pictures.
	*-- This is done by setting the PICTUREVAL
	*-- property of the IMAGE.
	.ADDOBJECT( 'IMG1', 'Image' )
	.Img1.PICTUREVAL = BlobTemp.PIC

	*-- Add an EditBox to display the raw
	*-- binary data directly out of the BLOB field.
	*-- This is not required, just fun to see the raw data.
	.ADDOBJECT( 'Edt1', 'EditBox' )
	.Edt1.MOVE(.Img1.WIDTH + 5, 0, .Img1.WIDTH, .Img1.HEIGHT)
	.Edt1.CONTROLSOURCE = 'BlobTemp.PIC'

	*-- Add record navigation buttons so that you can
	*-- move records in the cursor. The NAV class
	*-- is defined later in this code.
	.ADDOBJECT( 'NAV', 'NavBtns' )
	.NAV.MOVE( (.WIDTH - .NAV.WIDTH) + 13 , .Edt1.HEIGHT + 2 )

	.WIDTH = .Img1.WIDTH + .Edt1.WIDTH + 7
	*-- Make the form pretty by setting a few anchors
	*-- and setting MinWidth/Height.
	.NAV.ANCHOR = 192
	.Edt1.ANCHOR = 15
	.MINWIDTH = .WIDTH
	.MINHEIGHT = .HEIGHT
	.AUTOCENTER = .T.
	.CAPTION = 'Picture and Raw BLOB Data'
	.SETALL( 'VISIBLE', .T. )
ENDWITH

goForm.SHOW(1)
CLOSE DATA ALL


*--------------------------------
*-- This is just a subclass of the FoxPro Foundation Class
*-- named _DataNavBtns (located in HOME() + '\FFC\_datanav.vcx').
*-- This is where you redraw the BLOB data displayed by the IMAGE
*-- class by resetting the PICTUREVAL property of that class
*-- just before skipping records. Unlike an OLE Bound control populated
*-- by a GENERAL field, the IMAGE does not redraw its BLOB data automatically
*-- as the record pointer moves. This is how you force it.
DEFINE CLASS NavBtns AS _datanavbtns OF HOME() + '\FFC\_datanav.vcx'
	BORDERWIDTH = 0
	PROCEDURE EnableDisableButtons
		THIS.PARENT.Img1.PICTUREVAL = BlobTemp.PIC
		DODEFAULT()
ENDDEFINE
*
*------------ END CODE

?考

如需有關 PictureVal 屬性的詳細資訊,請造訪下列 Microsoft 網站]:
http://msdn2.microsoft.com/en-us/library/ms953566(vs.80).aspx (http://msdn2.microsoft.com/en-us/library/ms953566(vs.80).aspx)
如需詳細資訊請參閱隨附於 Visual FoxPro 9.0 Visual FoxPro 方案範例應用程式中 「 可停駐的映像檢視器 」 範例]。

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