FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Ampliar Imagen por zona de seleccion
Posts: 408
Joined: Fri Jan 29, 2010 08:14 PM
Ampliar Imagen por zona de seleccion
Posted: Sat Nov 27, 2010 04:07 AM

Hola a todos:

Tengo un dialogo donde muestro una imagen y unos botones de ampliar y reducir la imagen, hast aqui bien, pero:

Como puedo hacer que seleccionando con el raton una parte de la imagen se me amplie ese trozo unicamente? es como funcionan los programas de diseño. Estoy usando la clase TImage.

Muchas gracias de antemano.
JLL

Libreria: FWH/FWH1109 + Harbour 5.8.2 + Borland C++ 5.8.2
Editor de Recursos: PellecC
ADA, OURXDBU
S.O: XP / Win 7 /Win10
Blog: http://javierlloris.blogspot.com.es/
e-mail: javierllorisprogramador@gmail.com
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Ampliar Imagen por zona de seleccion
Posted: Sat Nov 27, 2010 11:10 AM
Saludos

te dejo un simple ejemplo
Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "Image.ch"

//----------------------------------------------------------------------------//

function Main()

   LOCAL oDlg, oImage
   LOCAL gcFile

   DEFINE DIALOG oDlg FROM 0, 0 TO 22, 60 ;
      TITLE FWDESCRIPTION + " JPG,JIF,GIF,BMP,DIB,RLE,TGA,PCX support!"

   @ 0, 0 IMAGE oImage SIZE 150, 150 OF oDlg SCROLL ADJUST

   ZoomZone():New( oImage )
   
   oImage:Progress( .f. )

   @ 1, 28 BUTTON "Select Image" SIZE 50,10 OF oDlg ACTION gcFile := GetImage( oImage )

   @ 2, 28 BUTTON "Reload" SIZE 50,10 OF oDlg ACTION If( gcFile != NIL, oImage:LoadBmp( gcFile ), )


   ACTIVATE DIALOG oDlg CENTER

return nil

//----------------------------------------------------------------------------//

function GetImage( oImage )

   local gcFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" +         ;
                             "DIB   (*.dib)| *.dib|" +          ;
                             "PCX   (*.pcx)| *.pcx|"  +         ;
                             "JPEG  (*.jpg)| *.jpg|" +          ;
                             "GIF   (*.gif)| *.gif|"  +         ;
                             "TARGA (*.tga)| *.tga|" +          ;
                             "RLE   (*.rle)| *.rle|" +          ;
                             "All Files (*.*)| *.*"             ;
                            ,"Please select a image file", 4 )

   if ! Empty( gcFile ) .and. File( gcFile )
      oImage:LoadBmp( gcFile )
   endif

return gcFile

//----------------------------------------------------------------------------//

function PrintImage( oImage )

   local oPrn

   PRINT oPrn NAME "Image Printing" PREVIEW
      PAGE
         oPrn:SayImage( 0, 0, oImage )
      ENDPAGE
   ENDPRINT

return nil

//----------------------------------------------------------------------------//

#define SRCCOPY      0x00CC0020

CLASS ZoomZone

   DATA oImage
   DATA nRow, nCol 
   DATA lPressed
   
   METHOD New()
   
   METHOD LButtonDown( nRow, nCol )
   METHOD LButtonUp( nRow, nCol )
   
   METHOD SelectZone( nRow, nCol )
   
ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( oImage ) CLASS ZoomZone

   ::oImage = oImage
   
   ::lPressed = .F.
   
   
   oImage:bMMoved    = {| nRow, nCol | ::SelectZone( nRow, nCol ) }
   oImage:bLClicked  = {| nRow, nCol | ::LButtonDown( nRow, nCol ) }
   oImage:bLButtonUp = {| nRow, nCol | ::LButtonUp( nRow, nCol ) }
   
RETURN Self

//----------------------------------------------------------------------------//

METHOD LButtonDown( nRow, nCol ) CLASS ZoomZone
   
   ::nRow = nRow
   ::nCol = nCol
   ::lPressed = .T.

RETURN nil

//----------------------------------------------------------------------------//

METHOD LButtonuP( nRow, nCol ) CLASS ZoomZone

   local hBmp, hBmpOld
   local hDCDesk := GetDC( GetDesktopWindow() )
   local hDCMem  := CreateCompatibleDC( hDCDesk )
   local hDCImg  := ::oImage:GetDC()
   local nLowRow, nHiRow, nLowCol, nHiCol
   
   hBmp = CreateCompatibleBitmap( hDCDesk, ::oImage:nWidth, ::oImage:nHeight )
   hBmpOld = SelectObject( hDCMem, hBmp )
   
   if ::nRow > nRow
      nLowRow = nRow + 1
      nHiRow  = ::nRow
   else 
      nLowRow = ::nRow + 1
      nHiRow  = nRow
   endif   

   if ::nCol > nCol
      nLowCol = nCol + 1
      nHiCol  = ::nCol
   else 
      nLowCol = ::nCol + 1
      nHiCol  = nCol
   endif      
   
   StretchBlt( hDCMem, 0, 0, ::oImage:nWidth, ::oImage:nHeight, ;
               hDCImg, nLowCol, nLowRow, nHiCol - nLowCol, nHiRow - nLowRow, SRCCOPY )  
   
    
   SelectObject( hDCMem, hBmpOld )
   DeleteObject( ::oImage:hBitmap )
   ::oImage:hBitmap = hBmp
   DeleteDC( hDCMem )
   ReleaseDC( GetDesktopWindow(), hDCDesk )
   ::oImage:ReleaseDC()

   ::lPressed = .F.
   ::oImage:Refresh()
   

RETURN nil

//----------------------------------------------------------------------------//

METHOD SelectZone( nRow, nCol ) CLASS ZoomZone

   local hDC 

   ::oImage:Refresh()
   SysRefresh()
   hDC :=  ::oImage:GetDC()
   if ::lPressed
      DrawDotedBox( hDC, ::nRow, ::nCol, nRow , nCol, 0 )
   endif
   ::oImage:ReleaseDC()

RETURN NIL

//----------------------------------------------------------------------------//

#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>

void WndDrawBox( HDC hDC, RECT * rct, HPEN hPUpLeft, HPEN hPBotRit );

HB_FUNC( DRAWDOTEDBOX ){
   RECT rct;
   COLORREF color =  ( COLORREF ) hb_parnl( 6 );
   HPEN hPen = CreatePen( PS_DOT, 1, color );
   
   rct.top    = hb_parni( 2 );
   rct.left   = hb_parni( 3 );
   rct.bottom = hb_parni( 4 );
   rct.right  = hb_parni( 5 );

   WndDrawBox( ( HDC ) hb_parnl( 1 ), &rct, hPen, hPen );

   DeleteObject( hPen );
   
}

#pragma ENDDUMP

//----------------------------------------------------------------------------//
Posts: 408
Joined: Fri Jan 29, 2010 08:14 PM
Re: Ampliar Imagen por zona de seleccion
Posted: Sat Nov 27, 2010 03:47 PM

Hola Daniel:

Que voy a decir de ti, excepto que eres un genio. Muchas gracias, sin tu ayuda en el foro, estariamos bien jodidos.

Yo lo lograba hacer que se marcara la zona con el raton.

Muchas gracias por tu tiempo y ayuda.

P.D Has mirado ya el tema del Cursor en el xBrowse?, bueno cuando lo mires ya me diras

Un saludo
JLL

Libreria: FWH/FWH1109 + Harbour 5.8.2 + Borland C++ 5.8.2
Editor de Recursos: PellecC
ADA, OURXDBU
S.O: XP / Win 7 /Win10
Blog: http://javierlloris.blogspot.com.es/
e-mail: javierllorisprogramador@gmail.com
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: Ampliar Imagen por zona de seleccion
Posted: Wed Nov 13, 2013 12:17 PM

DAniel,
When I zoom the image iti is wrong...How I can set the % of zoom ?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Ampliar Imagen por zona de seleccion
Posted: Wed Nov 13, 2013 01:04 PM
Silvio

the sample working fine to me...

the sample work selecting a image area, this image will be zoomed and fill all container area. The sample you can not catch and move the image only select a area to zoom

the function doing StretchBlt all magic

you can calculate percent of nWidth and nHeight and set the new value in function StretchBlt

Continue the discussion