Jump to content
Fivewin Brasil

carregar imagem salva no banco de dados em formato JPG E EXIBIR NO BROWSE


marcioe

Recommended Posts

Amigos, é assim, a imagem está salva no cadastro de produtos, porem queria exibir ela no grid do browse

a imagem exibida eu fiz o teste usando um BMP dai sim exibe, porem queia que fosse exibido JPG

aFotos_produtos:=SqlArray("SELECT FOTO FROM foto_produto order by ID_FOTO")

xbrowse(aFotos_produtos)


Sem-t-tulo.jpg

Hoje para gravar a foto é desta forma

*-------------------------------------------------------------------------------
* Gravar a foto do Produto
*-------------------------------------------------------------------------------
FUNCTION INSERE_APAGA_FOTO_PRODUTO(T_OPERACAO_PRODUTOS)
	T_ID_FOTO	:= 0    
	*----------------------------------------------------------------------------
	IF FSize(DRIVE_TR+"\"+CURDIR() + "\TMP_IMG.JPG") > 0
		BEGIN TRANSACTION
			cQuery_Mtabela  := 'DELETE from foto_produto where CODIGO_PRODUTO = ' +  TRANSFORMA_SQL(T_CODI_PRODUTOS,"N",06,0)  + ' LIMIT 1'
			COMITAR_DADOS_SQL(cQuery_Mtabela)
		END TRANSACTION
	   BEGIN TRANSACTION
			cQuery_Mtabela  := 						"INSERT INTO foto_produto ( "
			cQuery_Mtabela	 := cQuery_Mtabela + " CODIGO_PRODUTO 	"
			cQuery_Mtabela	 := cQuery_Mtabela + ",DATA_FOTO			"
			cQuery_Mtabela	 := cQuery_Mtabela + ",FOTO				"					
			cQuery_Mtabela	 := cQuery_Mtabela +	" ) VALUES ( "
			cQuery_Mtabela	 := cQuery_Mtabela +	TRANSFORMA_SQL(T_CODI_PRODUTOS,"N",06,0) 		+ ","
			cQuery_Mtabela	 := cQuery_Mtabela + TRANSFORMA_SQL(DATE(),"D",08,0) 					+ ","
			cQuery_Mtabela	 := cQuery_Mtabela + ANY2SQL( MemoRead( (T_FOTOGRAFIA) ) ) 
			cQuery_Mtabela	 := cQuery_Mtabela + " )"
			COMITAR_DADOS_SQL(cQuery_Mtabela)
		END TRANSACTION
		HB_GCAll(.T.)
	ENDIF	
RETURN .T.                                                           

 

Link to comment
Share on other sites

 

Amiguinhos,

Marcio

Carregue a imagem usando fRead() ou MemoRead(), converta com as funções Base64 que você usa no SAT e salve o resultado num campo Blob ou Varchar.

Como assim 
Eu gravo assim no banco de dados

BEGIN TRANSACTION
			cQuery_Mtabela  := 						"INSERT INTO foto_produto ( "
			cQuery_Mtabela	 := cQuery_Mtabela + " CODIGO_PRODUTO 	"
			cQuery_Mtabela	 := cQuery_Mtabela + ",DATA_FOTO			"
			cQuery_Mtabela	 := cQuery_Mtabela + ",FOTO				"					
			cQuery_Mtabela	 := cQuery_Mtabela +	" ) VALUES ( "
			cQuery_Mtabela	 := cQuery_Mtabela +	TRANSFORMA_SQL(T_CODI_PRODUTOS,"N",06,0) 		+ ","
			cQuery_Mtabela	 := cQuery_Mtabela + TRANSFORMA_SQL(DATE(),"D",08,0) 					+ ","
			cQuery_Mtabela	 := cQuery_Mtabela + ANY2SQL( MemoRead( (T_FOTOGRAFIA) ) ) 
			cQuery_Mtabela	 := cQuery_Mtabela + " )"
			COMITAR_DADOS_SQL(cQuery_Mtabela)
		END TRANSACTION
		HB_GCAll(.T.)
Link to comment
Share on other sites

Amiguinhos,

Marcio

Faça o teste e adaptação:

	Function EncodeFile( strPicPath )
   LOCAL adTypeBinary := 1 // Tipo Binary
	   // Variaveis para codificacao
   LOCAL objXML
   LOCAL objDocElem
	   // Variavel para ler o conteudo da imagem
   LOCAL objStream
	   // Abre data stream da imagem
   objStream := TOleAuto():New( "ADODB.Stream" )
   objStream:Type := adTypeBinary
   objStream:Open()
   objStream:LoadFromFile( strPicPath )
	   // Cria XML e node raiz
   // que ira conter o dado da imagem
   objXML := TOleAuto():New( "MSXml2.DOMDocument" )
   objDocElem := objXML:createElement( "Base64Data" )
   objDocElem.dataType := "bin.base64"
	   // Fixa o valor binario
   objDocElem:nodeTypedValue := objStream:Read()
	   // Pega o valor codificado em Base64
   EncodeFile := objDocElem:Text
   return nil

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...