Using function RectDotted( ::hWnd, ::nBoxTop, ::nBoxLeft, ::nBoxBottom, ::nBoxRight ), I've been able to draw a dotted rectangle on a timage being displayed on a window. I need to find a way to keep only this portion of the image. To this end I saw an idea using WndCopy4( ::hWnd, aRect ). But that copies the rectangle from the screen where the resolution might not be as good as the original bmp/jpg being displayed.
Can someone point me in the right direction as to how to read the selected rectangle from the bmp/jpg file instead of from the screen?
Here is the code I've been using:
- Code: Select all Expand view
- //----------------------------------------------------------------------------//
METHOD LButtonDown( nRow, nCol, nFlags ) CLASS TImage
if ::bLClicked != nil
Eval( ::bLClicked, nRow, nCol, nFlags )
else
::lBoxDraw = .t.
::nBoxTop = nRow
::nBoxLeft = nCol
::nBoxBottom = nRow
::nBoxRight = nCol
::Capture()
::DrawBox()
endif
return nil
//----------------------------------------------------------------------------//
METHOD MouseMove( nRow, nCol, nFlags ) CLASS TImage
if ::lBoxDraw
::DrawBox() //deletes existing dottedbox
::nBoxBottom := iif( ::nBoxBottom < nRow, nRow, ::nBoxBottom )
::nBoxRight := iif( ::nBoxRight < nCol, nCol, ::nBoxRight )
::nBoxTop := iif( ::nboxTop > nRow, nRow, ::nboxTop )
::nBoxLeft := iif( ::nBoxLeft > nCol, nCol, ::nBoxLeft )
::DrawBox() //redraws new dottedbox
endif
return Super:MouseMove( nRow, nCol, nFlags )
//----------------------------------------------------------------------------//
METHOD LButtonUp( nRow, nCol, nFlags ) CLASS TImage2
if ::lBoxDraw .and. ::nBoxTop <> ::nBoxBottom .and. ::nBoxLeft <> ::nBoxRight
::DrawBox()
::CopyRect( { ::nBoxTop, ::nBoxLeft, ::nboxBottom, ::nBoxRight } )
ReleaseCapture()
DrawFocusRect( ::hdc, { ::nBoxTop, ::nBoxLeft, ::nboxBottom, ::nBoxRight } )
::ScrollAdjust()
::refresh( .t. )
endif
::lBoxDraw = .f.
return nil
*-------------------------------------------------------------------------------------------------------------------------------
METHOD CopyRect( aRect ) CLASS TImage2
local hBmp := WndCopy4( ::hWnd, aRect )
Local cFile:= Temp_Name( "bmp" )
DibWrite( cfile, DibFromBitmap( hBmp ) )
DeleteObject( hBmp )
::loadImage( ,cfile)
::refresh()
ferase( cfile )
return nil
Thank you,
Reinaldo.