FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Seleccionar secciones de una imagen por parte del usuario
Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM

Seleccionar secciones de una imagen por parte del usuario

Posted: Mon Oct 10, 2016 01:12 PM

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,

Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM

Re: Seleccionar secciones de una imagen por parte del usuario

Posted: Mon Oct 10, 2016 03:04 PM
La clase scan tiene una opcion para seleccionar un area a scanear en base a la imagen que obtiene desde la vista previa del scanner.
Tal vez te pueda servir.
Code (fw): Select all Collapse
#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 coor
Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM

Re: Seleccionar secciones de una imagen por parte del usuario

Posted: Mon Oct 10, 2016 03:58 PM

Gracias, voy a estudiar el c贸digo.
Saludos,

Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM

Re: Seleccionar secciones de una imagen por parte del usuario

Posted: Tue Oct 11, 2016 06:34 AM

Siguiendo con el tema ... una vez tengo una parte seleccionada, 驴como har铆a para exportar ese "trozo" de imagen a un bmp o jpg?

Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM

Re: Seleccionar secciones de una imagen por parte del usuario

Posted: Tue Oct 11, 2016 12:02 PM
Angel
Existe 茅sta funci贸n, quiz谩s ayude.

Code (fw): Select all Collapse
SaveToBmp2( oWnd, "C:\IMAGEN.JPG" )
Saludos,



Adhemar C.
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM

Re: Seleccionar secciones de una imagen por parte del usuario

Posted: Tue Oct 11, 2016 03:04 PM
Deber铆as mirar la function

Code (fw): Select all Collapse
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 );


que te devuelve una referencia a una imagen con esas dimensiones

Code (fw): Select all Collapse
聽 hb_retnl( ( HB_LONG ) newImage );

}
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noci贸n del tiempo

El secreto de la felicidad no est谩 en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM

Re: Seleccionar secciones de una imagen por parte del usuario

Posted: Tue Oct 11, 2016 03:31 PM

Interesante cnavarro, sigo experimentando. Gracias.

Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4

Continue the discussion