Seleccionar secciones de una imagen por parte del usuario

Post Reply
User avatar
AngelSalom
Posts: 727
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España
Has thanked: 1 time
Contact:

Seleccionar secciones de una imagen por parte del usuario

Post by AngelSalom »

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
User avatar
cmsoft
Posts: 1297
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina
Been thanked: 2 times

Re: Seleccionar secciones de una imagen por parte del usuario

Post by cmsoft »

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: Select all | Expand

#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


 
User avatar
AngelSalom
Posts: 727
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España
Has thanked: 1 time
Contact:

Re: Seleccionar secciones de una imagen por parte del usuario

Post by AngelSalom »

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
User avatar
AngelSalom
Posts: 727
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España
Has thanked: 1 time
Contact:

Re: Seleccionar secciones de una imagen por parte del usuario

Post by AngelSalom »

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
User avatar
acuellar
Posts: 1645
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Seleccionar secciones de una imagen por parte del usuario

Post by acuellar »

Angel
Existe ésta función, quizás ayude.

Code: Select all | Expand


SaveToBmp2( oWnd, "C:\IMAGEN.JPG" )
 
Saludos,

Adhemar C.
User avatar
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: Seleccionar secciones de una imagen por parte del usuario

Post by cnavarro »

Deberías mirar la function

Code: Select all | Expand


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: Select all | Expand



  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
User avatar
AngelSalom
Posts: 727
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España
Has thanked: 1 time
Contact:

Re: Seleccionar secciones de una imagen por parte del usuario

Post by AngelSalom »

Interesante cnavarro, sigo experimentando. Gracias.
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
Post Reply