Posts: 1,000
Threads: 253
Joined: Feb 2008
I'd like to load up an image and drag a box to crop the image.
A larger look into what I am doing is I need to convert PDF files to TIFF files. The users do not have photo editing software. Some of files have extra stuff that need to be trimmed off the edges.
First with GhostScript a JPG is created from a PDF.
**QM will load the image into a dialog so the crop points can be determined by the user **
The final tiff image will be processed by GflAx.
Thanks,
Jim
Posts: 1,000
Threads: 253
Joined: Feb 2008
So the dialog just needs to be able to resize a box (control or whatever) over an image and the x y width height numbers get fed into GflAx.crop
-Jim
Posts: 12,147
Threads: 143
Joined: Dec 2002
Function
dialog_select_rectangle
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
str controls = "3"
str sb3
rget sb3 "Wallpaper" "Control Panel\Desktop"
if(!ShowDialog("dialog_select_rectangle" &dialog_select_rectangle &controls)) ret
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 Static 0x5400000E 0x0 0 0 16 16 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030506 "*" "" "" ""
ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_LBUTTONDOWN goto dragCrop
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
;dragCrop
type DSR2387 hwnd RECT'r __Hdc'hdc !notFirstTime
DSR2387 d.hwnd=id(3 hDlg)
POINT p; xm p d.hwnd 1; memcpy &d.r &p 8
d.hdc.Init(d.hwnd)
int ok=Drag(hDlg &DSR_Drag &d)
if(!ok or IsRectEmpty(&d.r)) ret
__MemBmp mb.Create(d.r.right-d.r.left d.r.bottom-d.r.top d.hdc d.r.left d.r.top)
SaveBitmap mb.bm "$temp$\crop.bmp"
run "$temp$\crop.bmp"
ret
Function
DSR_Drag
;/dialog_select_rectangle
function# button DSR2387&d
;Callback function for Drag.
;button - mouse button: 0 while dragging, 1 left up, 2 right up.
;param - param passed to Drag().
;Return:
;;;If button 0 (mouse move), return cursor handle, or 0 to not change cursor, or 1-3 to use standard cursors: 1 move, 2 copy, 3 no operation, 4,5 (QM 2.3.4) red and blue cross.
;;;Else (mouse button up), can return any value. Drag() returns it.
if(!d.notFirstTime) d.notFirstTime=1
else if(!IsRectEmpty(&d.r)) DrawFocusRect d.hdc &d.r ;;restore previous rect
sel button
,case 0
,POINT p; xm p d.hwnd 1; memcpy &d.r.right &p 8
,if(!IsRectEmpty(&d.r)) DrawFocusRect d.hdc &d.r ;;draw new rect
,ret 4
,
,case else
,ret button
Posts: 1,000
Threads: 253
Joined: Feb 2008
Works, but I'm having troubles figuring how to tweak so it performs with a few changes.
I'd like to size the image that displays in the dialog so it fits. (So the image loaded into the dialog is only a representation of what is going to be cropped)
The crop box should execute the crop on the original image to maintain high resolution.
I'd also like the crop box to draw a rectangle that can be tweaked then a button will execute the crop once all of the edges have been determined.
Thank you so much for this example!
-jim