Página 1 de 1
Select a part of image
Publicado: Mié Sep 14, 2011 3:02 pm
por franksoft
Hello, someone can give me some help?
I have an image loaded into a TBevel, how do I bring up a box that allows you to select a part of the image to obtain the coordinates (Left, Top, Right, Bottom) and then save the selected area in a file.bmp
I tried TCaptureBitmap developed by the excellent JLalin. I do not know if you can do this
Select a part of image
Publicado: Mié Sep 14, 2011 8:02 pm
por jlalin
Franco,
Add this datas to the form declaration:
DATA nX INIT -1
DATA nY INIT -1
DATA aSelect INIT { 0, 0, 0, 0 }
Select the TBevel and put this code in OnLButtonDown:
METHOD TBevel1LButtonDown( oSender, nKeyFlags, nPosX, nPosY ) CLASS ...
IF ::nX == -1
::nX := nPosX
::nY := nPosY
::aSelect[1] := nPosX
::aSelect[2] := nPosY
ELSE
::nX := -1
ENDIF
RETURN Nil
This code in OnMouseMove event:
METHOD TBevel1MouseMove( oSender, nKeyFlags, nPosX, nPosY ) CLASS ...
LOCAL hDC
IF ::nX != -1
::oBevel1:Redraw()
hDC := GetDC( ::oBevel1:Handle )
DrawFocusRect( hDC, { ::nX, ::nY, nPosX, nPosY } )
ReleaseDC( ::oBevel1:Handle, hDC )
::aSelect[3] := nPosX
::aSelect[4] := nPosY
ENDIF
RETURN Nil
Now to save it with TCaptureBitmap:
METHOD Button1Click( oSender ) CLASS ...
::aSelect[1] += ::oBevel1:nLeft
::aSelect[2] += ::oBevel1:nTop
::aSelect[3] += ::oBevel1:nLeft
::aSelect[4] += ::oBevel1:nTop
WITH OBJECT TCaptureBitmap():New
:Capture( ::Handle, { ::aSelect[1], ::aSelect[2], ::aSelect[3],
::aSelect[4] } )
:Save( "c:testscapture.bmp" )
//ShellExecute( , "open", "c:testscapture.bmp" )
END
RETURN Nil
And you are done.
Regards,
José Lalín
Select a part of image
Publicado: Jue Sep 15, 2011 6:47 pm
por franksoft
Josí¨,
your code is very helpful to me.
I only have a small problem with
WITH OBJECT TCaptureBitmap (): New
:Capture (:: Handle, {:: aSelect [1]:: aSelect [2]:: aSelect [3]
:: ASelect [4]})
The selected area is not captured but the whole form/oBevel1 as can be seen from the attached jpg.
Using the method Hardcopy (. T., "bmp captured"), opens with a blank page preview
i'm using Tcapturebitmap version 1.5.0.0 I do not know if it is updated
Regards,
Franco
Attached files
Select a part of image
Publicado: Jue Sep 15, 2011 9:18 pm
por jlalin
Franco,
check with the attached obj.
It it does not work then make a little project to see the problem and
export it (Project->Export with sources only) and send it to the forum so I
can test it.
Regards,
José Lalín
--
Select a part of image
Publicado: Vie Sep 16, 2011 8:45 am
por franksoft
Josí¨,
I attach a small project as you asked me
Regards,
Franco
Attached files DragDetect-1-0-0-0.zip (8.2 KB)Â
Select a part of image
Publicado: Vie Sep 16, 2011 9:07 am
por jlalin
Franco,
delete the capturebitmap.lib from the list of project libraries and add
this object file to the test. With it the test works nicely.
Regards,
José Lalín
--
Attached files CapBitmap.zip (2.7 KB)Â
Select a part of image
Publicado: Vie Sep 16, 2011 4:01 pm
por franksoft
Josí¨ the best!
Thanks so much
Regards,
Franco
Select a part of image
Publicado: Vie Sep 16, 2011 4:50 pm
por jlalin
Franco,
you're welcome!

Regards,
José Lalín
Select a part of image
Publicado: Vie Sep 23, 2011 6:42 pm
por franksoft
Hello, JLalin
I wish I could move or resize TLabel, inserted at runtime into a TBevel, but I do not know how to identify the component.
Can you give me a little help?
Regards,
Frank
P.S. EXAMPLE ENCLOSE
Attached files DragDetect-1-0-0-0.zip (28.4 KB)Â
Select a part of image
Publicado: Lun Sep 26, 2011 11:22 am
por jlalin
Franco,
I just modified it to show you how to detect the label.
Regards,
José Lalín
--
Attached files Drag.zip (2.2 KB)Â
Select a part of image
Publicado: Mié Sep 28, 2011 11:47 am
por franksoft
Hi Josí¨,
thank you for your helpful suggestions
I changed code as attached, but I still have problems with positioning and sizing especially by moving the mouse quickly.
I do not know if I have taken the right path.
Thanks again for your time
Regards,
Frank
Attached files DragDetect-1-0-0-0.zip (29.4 KB)Â
Select a part of image
Publicado: Mié Sep 28, 2011 12:44 pm
por jlalin
Franco,
sorry, never did something like that and can't figure a way to do it.
Try adding a SetCapture( oSender:Handle ) in OnRDown and ReleaseCapture()
in OnRUp() or even in the OnMouseMove methods but don't know if it will work.
Regards,
José Lalín
Select a part of image
Publicado: Vie Sep 30, 2011 7:19 pm
por franksoft
Hello Jose,
If you are interested and can be helpful, here is how I solved.
I enclose small example
Regards
Franco
Attached files MoveResize-1-0-0-0.zip (2.7 KB)Â
Select a part of image
Publicado: Lun Oct 03, 2011 3:24 pm
por jlalin
Franco,
good job! Congrats!
Regards,
José Lalín
Select a part of image
Publicado: Mié Oct 19, 2011 11:30 am
por ramonb
Jlalin gave right and useful information.