In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

Select a part of image

Xailer English public forum
Responder
franksoft
Mensajes: 42
Registrado: Lun Sep 05, 2011 6:45 pm

Select a part of image

Mensaje 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
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Select a part of image

Mensaje 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
franksoft
Mensajes: 42
Registrado: Lun Sep 05, 2011 6:45 pm

Select a part of image

Mensaje 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
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Select a part of image

Mensaje 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
--
franksoft
Mensajes: 42
Registrado: Lun Sep 05, 2011 6:45 pm

Select a part of image

Mensaje 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)Â
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Select a part of image

Mensaje 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)Â
franksoft
Mensajes: 42
Registrado: Lun Sep 05, 2011 6:45 pm

Select a part of image

Mensaje por franksoft »

Josí¨ the best!
Thanks so much
Regards,
Franco
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Select a part of image

Mensaje por jlalin »

Franco,
you're welcome! :-D
Regards,
José Lalí­n
franksoft
Mensajes: 42
Registrado: Lun Sep 05, 2011 6:45 pm

Select a part of image

Mensaje 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)Â
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Select a part of image

Mensaje 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)Â
franksoft
Mensajes: 42
Registrado: Lun Sep 05, 2011 6:45 pm

Select a part of image

Mensaje 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)Â
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Select a part of image

Mensaje 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
franksoft
Mensajes: 42
Registrado: Lun Sep 05, 2011 6:45 pm

Select a part of image

Mensaje 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)Â
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Select a part of image

Mensaje por jlalin »

Franco,
good job! Congrats!
Regards,
José Lalí­n
ramonb
Mensajes: 1
Registrado: Mié Oct 19, 2011 11:14 am

Select a part of image

Mensaje por ramonb »

Jlalin gave right and useful information.
Ramon Boyd
Responder