Dica do SistemaEste artigo aplica-se a um sistema operativo diferente do que está a utilizar. Foi desactivado o conteúdo do artigo, que pode não ser relevante para si.
Microsoft Visual FoxPro 9.0 apresenta o tipo de dados do blob . Pode utilizar campos blob para armazenar dados binários, tais como imagens. Imagens que são armazenadas num campo blob podem ser impressos em mapas e apresentadas em formulários. Este artigo descreve como imprimir imagens e como apresentar imagens que são armazenadas num campo blob .
Visual FoxPro 9.0 apresenta o tipo de dados do blob . Pode utilizar campos blob para armazenar dados binários de qualquer tipo e comprimento indeterminado. Por exemplo, pode armazenar imagens num campo blob .
Pode imprimir as imagens que são armazenadas num campo blob num relatório utilizando o controlo Dependente de imagem/OLE . Para imprimir as imagens que são armazenadas num campo blob , terá de definir origem do controlo do controlo OLE/imagem dependente que está a ser utilizado como uma referência de objecto. A referência de objecto tem de ser para uma instância de um controlo de imagem . A propriedade PictureVal desta instância deve ser definida para um campo blob que contém as imagens.
Pode apresentar imagens que são armazenadas num campo blob num formulário utilizando o controlo de imagem . Coloque o controlo de imagem directamente para o formulário e definir a propriedade PictureVal do controlo de imagem . Isto destina-se ligar o controlo de imagem ao campo blob . No entanto, são necessários para forçar o controlo de imagem para redesenhar à medida que o ponteiro de registo se desloca na tabela que contém o campo blob passos adicionais.
Os seguintes exemplos de código são concebidos para Visual FoxPro 9.0. Estes exemplos de código mostram como imprimir imagens e como apresentar imagens que estão armazenadas como dados binários num campo blob . Para testar estes exemplos, siga estes passos:
Inicie o Visual FoxPro 9.0 e criar dois novos programas.
Copie e cole exemplo 1 dos novos programas.
Copiar e, em seguida, colá exemplo 2 o programa de novo.
Exemplo 1: Imprimir as imagens que são armazenadas num campo BLOB num relatório
O código de exemplo seguinte mostra como imprimir imagens que estão armazenadas como dados binários num campo blob num relatório.
*------------ 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
Exemplo 2: Apresentar imagens que são armazenadas num campo BLOB num formulário
O código de exemplo seguinte mostra como apresentar imagens que estão armazenadas como dados binários num campo blob num formulário.
*------------ 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
Para mais informações, consulte o exemplo de "Visualizador de imagens puder ser ligado a estação de ancoragem" na aplicação Visual FoxPro solução exemplos incluída no Visual FoxPro 9.0.
IMPORTANTE: Este artigo foi traduzido por um sistema de tradução automática (também designado por Machine translation ou MT), não tendo sido portanto revisto ou traduzido por humanos. A Microsoft tem artigos traduzidos por aplicações (MT) e artigos traduzidos por tradutores profissionais. O objectivo é simples: oferecer em Português a totalidade dos artigos existentes na base de dados do suporte. Sabemos no entanto que a tradução automática não é sempre perfeita. Esta pode conter erros de vocabulário, sintaxe ou gramática? erros semelhantes aos que um estrangeiro realiza ao falar em Português. A Microsoft não é responsável por incoerências, erros ou estragos realizados na sequência da utilização dos artigos MT por parte dos nossos clientes. A Microsoft realiza actualizações frequentes ao software de tradução automática (MT). Obrigado.
Clique aqui para ver a versão em Inglês deste artigo: 895602
(http://support.microsoft.com/kb/895602/en-us/
)
Qual foi o esforço que despendeu pessoalmente para utilizar este artigo?
Muito baixo
Baixo
Moderado
Elevado
Muito elevado
Diga-nos porquê e o que podemos fazer para melhorar estas informações
Obrigado! Os seus comentários são utilizados para ajudar-nos a melhorar o conteúdo do nosso suporte. Para obter mais opções de assistência, visite a Home Page de Ajuda e Suporte.