Image File
Moderator: Rathinagiri
Image File
Hi All ,
What type field can save image file ? and how ?
I use dbf file.
Regards,
Tristan
What type field can save image file ? and how ?
I use dbf file.
Regards,
Tristan
Re: Image File
Hello Tristan,Tristan wrote:Hi All ,
What type field can save image file ? and how ?
I use dbf file.
> What type field can save image file ?
Memo field, of course.
Try the following self-sufficient sample contributed by CAS:
Code: Select all
#include "MiniGUI.ch"
memvar m_ver, p_GetFile
proc main
local x_arq := 'config.dbf'
REQUEST DBFCDX, DBFFPT
RDDSETDEFAULT( "DBFCDX" )
SET MULTIPLE OFF WARNING
if !file ( x_arq )
DBCREATE( x_arq , { ;
{"ROW" , "N" , 9 , 3} ,;
{"COL" , "N" , 9 , 3} ,;
{"WIDTH" , "N" , 9 , 3} ,;
{"HEIGHT" , "N" , 9 , 3} } )
end
x_arq := 'arq.dbf'
if !file ( x_arq )
DBCREATE( x_arq , { ;
{"NOME" , "C" , 254 , 0} ,;
{"IMAGEM" , "M" , 10 , 0} } )
end
use &x_arq alias IMAGE new exclusive
index on field->nome tag image to image
public m_ver := GetStartupFolder() + '_cas_ver.JPG', p_GetFile := ''
SET DATE BRITISH
SET CENTURY ON
SET DELETED ON
SET BROWSESYNC ON
Define window Form_1 ;
At 0, 0 Width 700 Height 500 ;
on init f_init() ;
on release f_release() ;
nosysmenu ;
Title 'IMAGE to DBF - by cas.soft@gmail.com' Main
@ 01,1 button btn_read caption 'Importar' action f_importar()
@ 30,1 button btn_save caption 'Exportar' action f_exportar()
@ 60,1 button btn_dele caption 'Apagar' action f_apagar()
@ 90,1 button btn_sair caption 'Sair' action thiswindow.release
@ 1,120 image img_cas picture ''
@ 128,1 BROWSE Browse_1 ;
WIDTH 690 ;
HEIGHT 330 ;
HEADERS { 'Arquivo'} ;
WIDTHS { 668 } ;
VALUE 1 ;
WORKAREA IMAGE ;
FIELDS { 'NOME' } ;
ON CHANGE browse_1_change() ;
LOCK ;
EDIT INPLACE
Define context menu
Item "Importar" Action f_importar()
Item "Exportar" Action f_exportar()
Item "Apagar" Action f_apagar()
Item "Sair" Action thiswindow.release
End Menu
Define timer timer_1 ;
interval 250 ;
action ( setforegroundwindow( getformhandle('form_1') ), form_1.timer_1.release )
End Window
form_1.browse_1.setfocus
form_1.Center
form_1.Activate
Return
*..............................................................................................*
func f_init
local bkp_alias := alias()
local m_row
local m_col
local m_width
local m_height
sele 0
use config
if lastrec() # 0
m_row := FIELD->ROW
m_col := FIELD->COL
m_width := FIELD->WIDTH
m_height:= FIELD->HEIGHT
else
m_row := 100
m_col := 200
m_width := 300
m_height:= 400
end
use
sele &bkp_alias
Define window Form_2 ;
At m_row, m_col Width m_width Height m_height ;
title 'CAS' ;
on init f_size() ;
on maximize f_size() ;
on size f_size() ;
nosysmenu ON INTERACTIVECLOSE .f. child
@ 0,0 image img_cas picture ''
End Window
form_1.browse_1.value := 1
form_1.browse_1.setfocus
form_2.activate
retu nil
*..............................................................................................*
func f_size
form_2.img_cas.width := form_2.width - 8
form_2.img_cas.height := form_2.height - 8
form_2.img_cas.picture := m_ver
retu nil
*..............................................................................................*
func f_apagar
if empty( lastrec() )
retu nil
end
repl NOME with ''
repl IMAGEM with ''
dele
pack
go top
form_1.browse_1.value := recno()
form_1.browse_1.refresh
if empty(form_1.browse_1.value)
form_1.img_cas.picture := ''
form_1.img_cas.hide
form_1.img_cas.show
form_2.img_cas.picture := ''
form_2.img_cas.hide
form_2.img_cas.show
form_2.title := ''
end
retu nil
*..............................................................................................*
func f_exportar
local a_arqs := { ;
{ "Image Files" , "*.JPG;*.BMP;*.GIF;*.ICO" } ,;
{ "Arquivos JPG" , "*.JPG" } ,;
{ "Arquivos BMP" , "*.BMP" } ,;
{ "Arquivos GIF" , "*.GIF" } ,;
{ "Arquivos ICO" , "*.ICO" } } ,;
m_novo := alltrim( IMAGE->NOME ) , cFile
if empty( lastrec() )
retu nil
end
cFile := Putfile( a_arqs ,;
'Salvar Arquivo como...' , GetCurrentFolder() , .f. , m_novo )
if empty( cFile )
retu nil
end
if file( cFile )
MsgStop( "Arquivo jб existe", "Erro", , .f. )
else
MemoWrit( cFile , UnMaskBinData( FIELD->IMAGEM ) )
end
retu nil
*..............................................................................................*
func browse_1_change
MemoWrit( m_ver , UnMaskBinData( FIELD->IMAGEM ) )
form_1.img_cas.picture := m_ver
form_2.img_cas.picture := m_ver
form_2.title := trim(IMAGE->NOME)
retu nil
*.................................................................*
proc f_release
close all
erase &m_ver
if .not. file('config.dbf')
return
end
use config
if lastrec() = 0
append blank
end
repl ROW with form_2.row
repl COL with form_2.col
repl WIDTH with form_2.width
repl HEIGHT with form_2.height
return
*.................................................................*
function MaskBinData( x ) && Nгo lembro quem fez
x := StrTran( x , chr(26) , '\\#26//' )
x := StrTran( x , chr(00) , '\\#00//' )
return x
*.................................................................*
function UnMaskBinData( x ) && Nгo lembro quem fez
x := StrTran( x , '\\#26//' , chr(26) )
x := StrTran( x , '\\#00//' , chr(00) )
return x
*.................................................................*
func f_importar
local varios := .t. && selecionar varios arquivos
local arq_cas := {}, i, n_for, File_cas, m_rat
p_GetFile := iif( empty( p_GetFile ) , GetMyDocumentsFolder() , p_GetFile )
arq_cas := GetFile ( { ;
{'Image Files' , '*.JPG;*.BMP;*.GIF;*.ICO'} ,;
{'JPG Files' , '*.JPG'} ,;
{'BMP Files' , '*.BMP'} } ,;
'Open File(s)' , p_GetFile , varios , .t. )
if len( arq_cas ) = 0
return nil
endif
for n_for := 1 to len( arq_cas )
i = n_for + 1
if n_for = len(arq_cas) && esta consistencia foi feita pq o ultimo arquivo
i = 1 && й sempre o primeiro
endif
File_cas := strtran( arq_cas[ i ] , '\\' , '\' )
append blank
m_rat := rat( '\' , File_cas )
if m_rat # 0
repl NOME with substr( File_cas , m_rat + 1 )
else
repl NOME with File_cas
end
repl IMAGEM with MaskBinData( MemoRead( File_cas ) )
next
m_rat = rat('\',arq_cas[1])
p_GetFile := left( arq_cas[1] , m_rat-1 )
form_1.browse_1.value := recno()
form_1.browse_1.refresh
retu nil
Kind Regards,
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
- Roberto Lopez
- HMG Founder
- Posts: 4004
- Joined: Wed Jul 30, 2008 6:43 pm
Re: Image File
This is only a personal opinion.Tristan wrote:Hi All ,
What type field can save image file ? and how ?
I use dbf file.
Regards,
Tristan
I've attempted (some years ago) to store pictures for about 1000 records in Visual FoxPro memo and it was a complete disaster.
I've attempted again (some months ago) with MySql, retrieving the images with PHP for web browser clients and it was a disaster too.
I've solved both situations, storing only image names and paths in the table and managing it as individual files from names stored.
In both cases, the images were about 10 per record and about 100kb each.
Regards,
Roberto.
Regards/Saludos,
Roberto
(Veritas Filia Temporis)
Roberto
(Veritas Filia Temporis)
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: Image File
In the case of MySQL, I had done one project successfully that I would share with a suitable example soon.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
Re: Image File
Hello Master Roberto,
With best regards.
Sudip
I also faced the same problem with Visual Foxpro and solved exactly the way you mentioned (by storing image names and paths). This software is still running and competing with ERPs, 100 times costlier than my project.Roberto Lopez wrote: This is only a personal opinion.
I've attempted (some years ago) to store pictures for about 1000 records in Visual FoxPro memo and it was a complete disaster.
I've attempted again (some months ago) with MySql, retrieving the images with PHP for web browser clients and it was a disaster too.
I've solved both situations, storing only image names and paths in the table and managing it as individual files from names stored.
In both cases, the images were about 10 per record and about 100kb each.
With best regards.
Sudip
With best regards,
Sudip
Sudip
Re: Image File
Yes Rathi, I am waiting for it ...rathinagiri wrote:In the case of MySQL, I had done one project successfully that I would share with a suitable example soon.
Regards.
Sudip
With best regards,
Sudip
Sudip
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: Image File
Bravo Sudip.sudip wrote:This software is still running and competing with ERPs, 100 times costlier than my project.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: Image File
Even though, I had stored images as such in the database, while using I used to extract them into individual files, before using them.
I had used "LOAD_FILE()" function of MySQL to load the image file into BLOB type of any size. While retrieving I used "select ... into DUMPFILE" syntax to store the images back in the working directory. In both the cases, Harbour is not involved.
I had used "LOAD_FILE()" function of MySQL to load the image file into BLOB type of any size. While retrieving I used "select ... into DUMPFILE" syntax to store the images back in the working directory. In both the cases, Harbour is not involved.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
Re: Image File
Hello Grigory Filatov,
Excellent sample code. It will be extremely helpful for my future projects. It's running very fast!!!
I learned many things from it
Thanks a lot.
With best regards to all.
Sudip
Excellent sample code. It will be extremely helpful for my future projects. It's running very fast!!!
I learned many things from it
Thanks a lot.
Yes Rathi, Very good news I am interested with "LOAD_FILE()" and "select .... into DUMPFILE"rathinagiri wrote:Even though, I had stored images as such in the database, while using I used to extract them into individual files, before using them.
I had used "LOAD_FILE()" function of MySQL to load the image file into BLOB type of any size. While retrieving I used "select ... into DUMPFILE" syntax to store the images back in the working directory. In both the cases, Harbour is not involved.
With best regards to all.
Sudip
With best regards,
Sudip
Sudip
Re: Image File
Yes, I too followed the same method while creating my Members' Entry Form in HMG (I've uploaded the initial coding also sometime back). This makes easy maintenance & their is no load on the data files. This way we can replace any current picture with a new one also, without going into the "modify" mode of that entry module. Just have to keep the same name for the new photo. Moreover if you are sending data from one place to another, you may not need to send the entire picture folder everytime. Eventually making the data size small.Roberto Lopez wrote:This is only a personal opinion.Tristan wrote:Hi All ,
What type field can save image file ? and how ?
I use dbf file.
Regards,
Tristan
I've attempted (some years ago) to store pictures for about 1000 records in Visual FoxPro memo and it was a complete disaster.
I've attempted again (some months ago) with MySql, retrieving the images with PHP for web browser clients and it was a disaster too.
I've solved both situations, storing only image names and paths in the table and managing it as individual files from names stored.
In both cases, the images were about 10 per record and about 100kb each.
Regards,
Roberto.
Regards,
Swapan