Buenas amigos, existe alguna clase o posibilidad de que, a partir de una imagen, el usuario pueda seleccionar zonas (rectangulares) de la misma para luego exportarlas. Lo que viene ser el "Seleccionar" del Paint, vamos ...
Gracias,
Buenas amigos, existe alguna clase o posibilidad de que, a partir de una imagen, el usuario pueda seleccionar zonas (rectangulares) de la misma para luego exportarlas. Lo que viene ser el "Seleccionar" del Paint, vamos ...
Gracias,
#include "FiveWin.ch"
Class SeleArea
data oImage
data uno,dos
data x1,y1,x2,y2,x0,y0
data cFile, nType, nRes, lHide, cdir,lemail,lvisu
data paginas,ultimo
method new() constructor
method raton(como,nRow,nCol,osay)
method raton2(como,nRow,nCol,osay)
method refresh()
method RegionSet( oScan )
method Ratio( oScan )
method flechas( nkey,lShift )
method coordenadas( )
method select_on() INLINE ( ::uno:= .t., ::dos:= .t. )
endclass
// -------------------------------------------------------------------------- //
method new() class SeleArea
::uno:=.f.
::dos:=.f.
::paginas:= {}
::ultimo:=""
return self
// -------------------------------------------------------------------------- //
method refresh() class SeleArea
::oimage:refresh()
SysRefresh()
if ::uno
if ::dos
::oimage:line(::y1,::x1,::y1,::x2)
::oimage:line(::y2,::x1,::y2,::x2)
::oimage:line(::y2,::x1,::y1,::x1)
::oimage:line(::y2,::x2,::y1,::x2)
else
::oimage:line(::y1,::x0,::y1,::x1)
::oimage:line(::y0,::x0,::y0,::x1)
::oimage:line(::y0,::x1,::y1,::x1)
::oimage:line(::y0,::x0,::y1,::x0)
endif
endif
return self
// -------------------------------------------------------------------------- //
method raton(como,y,x,osay) class SeleArea
if como="M"
if ( ::uno .and. !::dos )
::x0:=x
::y0:=y
::refresh()
endif
endif
if como="D"
::oimage:setfocus()
if ::dos
::uno:= .t.
::dos:= .f.
else
::uno:=.t.
::dos:=.f.
endif
::x1:=x
::y1:=y
osay[3]:settext("Arrastra el rat贸n hasta la otra esquina")
endif
if como="U"
if ( abs(::x1-x)>5.and.abs(::y1-y)>5 ) .and. ::uno
::dos:=.t.
::x2:=x
::y2:=y
osay[3]:settext("Ajuste fino: Con las flechas y SHIFT+flechas")
else
::uno:=.f.
::dos:=.f.
osay[3]:settext("Puedes seleccionar area a escanear con el rat贸n")
endif
::refresh()
endif
return self
// -------------------------------------------------------------------------- //
method raton2(como,y,x,osay) class SeleArea
local dif:= 25
local cerca:=.f.
if x > 439 - dif .and. x < 810 + dif .and. y > 15 - dif .and. y < 520 + dif
cerca:=.t.
endif
x:= if( x < 439 , 0 , if( x > 810 , 365 , (x - 439) / (810-439) * 365 ) )
y:= if( y < 15 , 0 , if( y > 520 , 499 , (y - 15) / (520- 15) * 499 ) )
// ::osay[1]:settext("X: "+tran(x,"9999")+" Y: "+tran(y,"9999"))
if como="M"
if ( ::uno .and. !::dos )
::x0:=x
::y0:=y
if !cerca
::dos:=.t.
::x2:=x
::y2:=y
osay[3]:settext("Ajuste fino: Con las flechas y SHIFT+flechas")
endif
::refresh()
endif
endif
if como="D"
if cerca
::uno:=.t.
::dos:=.f.
::x1:=x
::y1:=y
osay[3]:settext("Arrastra el rat贸n hasta la otra esquina")
endif
endif
if como="U"
if cerca
if ( abs(::x1-x)>5.and.abs(::y1-y)>5 ) .and. ::uno
::dos:=.t.
::x2:=x
::y2:=y
osay[3]:settext("Ajuste fino: Con las flechas y SHIFT+flechas")
else
::uno:=.f.
::dos:=.f.
osay[3]:settext("Puedes seleccionar area a escanear con el rat贸n")
endif
::refresh()
endif
endif
// endif
return self
// -------------------------------------------------------------------------- //
method ratio( oScan ) class SeleArea
local nLeft,nTop, nRigth, nBottom
local factor_hor , factor_ver
local rratio
oScan:OpenDefault()
oScan:RegionGetDefault(@nLeft,@nTop,@nRigth,@nBottom)
if ::dos
factor_hor:= nRigth / 365
factor_ver:= nBottom / 499
if ::x1 < ::x2
nleft:= ::x1 * factor_hor
nRigth:= ::x2 * factor_hor
else
nleft:= ::x2 * factor_hor
nRigth:= ::x1 * factor_hor
endif
if ::y1 < ::y2
ntop:= ::y1 * factor_ver
nbottom:= ::y2 * factor_ver
else
ntop:= ::y2 * factor_ver
nbottom:= ::y1 * factor_ver
endif
endif
rratio:= (nrigth-nleft)/(nbottom-ntop)
return rratio
// -------------------------------------------------------------------------- //
method RegionSet( oScan ) class SeleArea
local nLeft,nTop, nRigth, nBottom
local factor_hor , factor_ver
if ::dos
oScan:RegionGetDefault(@nLeft,@nTop,@nRigth,@nBottom)
factor_hor:= nRigth / 365
factor_ver:= nBottom / 499
if ::x1 < ::x2
nleft:= ::x1 * factor_hor
nRigth:= ::x2 * factor_hor
else
nleft:= ::x2 * factor_hor
nRigth:= ::x1 * factor_hor
endif
if ::y1 < ::y2
ntop:= ::y1 * factor_ver
nbottom:= ::y2 * factor_ver
else
ntop:= ::y2 * factor_ver
nbottom:= ::y1 * factor_ver
endif
oScan:RegionSet( nLeft,nTop, nRigth, nBottom )
else
oScan:RegionReset()
endif
return self
// -------------------------------------------------------------------------- //
method flechas( nkey,lShift ) class SeleArea
local nFor
if ::dos
do case
case nkey= VK_RIGHT
if ::x1 > ::x2
if ::x1 <365
::x1 ++
if !lShift
::x2 ++
endif
endif
else
if ::x2 <365
::x2 ++
if !lShift
::x1 ++
endif
endif
endif
case nkey= VK_LEFT
if ::x1 < ::x2
if lShift
if ::x2 > ::x1+5
::x2 --
endif
else
if ::x1 > 1
::x1 --
::x2 --
endif
endif
else
if lShift
if ::x1 > ::x2+5
::x1 --
endif
else
if ::x2 > 1
::x1 --
::x2 --
endif
endif
endif
case nkey= VK_DOWN
if ::y1 > ::y2
if ::y1 <499
::y1 ++
if !lShift
::y2 ++
endif
endif
else
if ::y2 <499
::y2 ++
if !lShift
::y1 ++
endif
endif
endif
case nkey= VK_UP
if ::y1 < ::y2
if lShift
if ::y2 > ::y1+5
::y2 --
endif
else
if ::y1 > 1
::y1 --
::y2 --
endif
endif
else
if lShift
if ::y1 > ::y2+5
::y1 --
endif
else
if ::y2 > 1
::y1 --
::y2 --
endif
endif
endif
endcase
::refresh()
endif
return self
// -------------------------------------------------------------------------- //
method coordenadas( ) class SeleArea
local coor
if ::uno .and. ::dos
coor:= { ::y1 , ::x1 , ::y2, ::x2 }
else
coor:={0,0,0,0}
endif
return coorGracias, voy a estudiar el c贸digo.
Saludos,
Siguiendo con el tema ... una vez tengo una parte seleccionada, 驴como har铆a para exportar ese "trozo" de imagen a un bmp o jpg?
SaveToBmp2( oWnd, "C:\IMAGEN.JPG" )GDIPLUSCAPTURERECTWND
{
HWND hWnd = ( HWND ) fw_parH( 1 ) ;
int nTop = hb_parni( 2 );
int nLeft = hb_parni( 3 );
int nWidth = hb_parni( 4 );
int nHeight = hb_parni( 5 );聽 hb_retnl( ( HB_LONG ) newImage );
}Interesante cnavarro, sigo experimentando. Gracias.