Load, show in dialog, interactively crop and save cropped

Load, show in dialog, interactively crop and save cropped

Postby codemaker » Wed Jun 27, 2012 8:00 pm

I am not sure we can do this, but I need it badly:

1. Load the image and show it on dialog (BMP file type)
2. The user can use the mouse to select an area of an image showed, to be cropped
3. Click on button or mouse right click or any other way - crop selected area
4. Cropped area should be saved to the selected folder under some name (BMP file type)

Anybody can help with this please?

Boris
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Load, show in dialog, interactively crop and save cropped

Postby Gale FORd » Wed Jun 27, 2012 8:34 pm

If you look at my sample program it lets you use a mouse to select an area with a dotted line that stays on the screen. Then you can press the ocr button to convert the area to text.
You could easily change from ocr area to save the area to new image. In fact there was a bug in the software that forced me to make a copy of that selected area before I ocr it.
The selected area even stays correct when the image is re-sized.

http://code.google.com/p/fivewin-contributions/downloads/detail?name=testscancomplete.zip&can=2&q=
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Load, show in dialog, interactively crop and save cropped

Postby codemaker » Wed Jun 27, 2012 9:46 pm

Gale, this looks very interesting.
I cannot see how to crop the image and save it under another name?

Also, when trying to recompile, I got the missing "ResizeBmp()" and "CreateDiBitmap()"

Any advice?
Can you add the functionality to be able to also CROP and SAVE a bitmap after the user selects the region?

Thanks
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Load, show in dialog, interactively crop and save cropped

Postby Gale FORd » Wed Jun 27, 2012 11:38 pm

I am pretty busy right now but I will see what I can do.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Load, show in dialog, interactively crop and save cropped

Postby ukoenig » Thu Jun 28, 2012 7:13 am

Maybe that works for You :?:

a Part of my Image-converter, to include in Your Application
Format-convert, Crop and Resize.
Full Souce is included :

viewtopic.php?f=3&t=22254&p=118473&hilit=crop#p118473

Best Regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Load, show in dialog, interactively crop and save cropped

Postby codemaker » Thu Jun 28, 2012 12:02 pm

Thanks Uwe,
will give it a try, looks very promissing...
Whyt xHb + FWH version do I need for this?

Boris
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Load, show in dialog, interactively crop and save cropped

Postby ukoenig » Thu Jun 28, 2012 12:15 pm

Boris,

nothing special included, I think it will work as soon TSelex is supported.
Just try to recompile.
Please check the makefile. I changed the path-define on top
to support new FWH-releases like :

c_path := GETCURDIR()
IF !FILE( c_path + "\NCONVERT.EXE" )
c_path := CURDRIVE() + ":\" + GETCURDIR()
ENDIF


I'm just working on a update :
mouseclick < top / left > and < bottom / right > for the crop-area, will draw a box.
For the moment only the values are shown.

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Load, show in dialog, interactively crop and save cropped

Postby codemaker » Thu Jun 28, 2012 2:01 pm

Uwe,

1. I just tested your EXE and I cannot crop anything from the selected image.
For example I loaded OLGA.JPG and tried to crop only the eyes out.
I click "crop" and the dialog opens with values to "draw a box". I selected something which would fit into the image (1,1, 50,50 - t,l,b,r) and hit "crop" on the right side of this dialog.
Then,new dialog opens which states that OLGA.JPG was copied to OLGA_1.JPG and also there is a field for Drive and the new file name if I want.
Whatever I do, the resulting image is the same as it was before cropping :(
I am probably missing something.

2. Another thing is that the RMK file requires BCC which I don't use and cannot try to recompile
Is there any chance you can make it by xHarbour other than BCC linker? I am using xBuildW here?

Yes, it would be excellent if we can have a box arround the area we selected to crop, the way as it is now, is very hard to use

Please, let me know what you can do. Especially with point 1 but also point 2 is very important to me.

Thank you
Boris
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Load, show in dialog, interactively crop and save cropped

Postby codemaker » Thu Jun 28, 2012 3:28 pm

Uwe,

I managed to compile using xBuildW and it works ok.
The problem that nothing happens no mater what I do (doesn't save cropped part or resized image, always save the same image as the original
Maybe I am not doing right something

Also, the Help.EXE you provided contains malvare! Avast reports it when I tried to unpack it from ZIP file or run it
Probably got infected somewhere on the road...

Boris
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Load, show in dialog, interactively crop and save cropped

Postby Marcelo Via Giglio » Thu Jun 28, 2012 4:02 pm

Hola

try to crop jgp image with this

Code: Select all  Expand view

FUNCTION cropImage( cSrcFile, nLeft, nTop, nRight, nBottom ,cDstFile )

   hLib = LOADLIB32( "freeimage.dll" )
   FI_JPGCROP( cSrcFile, cDstFile, nLeft, nTop, nRight, nBottom )
   FREELIBRARY( hLib )

RETURN NIL
 


and the freeimage mapped function is

Code: Select all  Expand view
DLL32 FUNCTION FI_JpgCrop( cSource AS LPSTR, cDest AS LPSTR, nLeft AS LONG, nTop AS LONG, nRight AS LONG, nBottom AS LONG ) ;
                                AS BOOL ;
                                PASCAL FROM "_FreeImage_JPEGCrop@24" LIB hLib
 


This function save the croped image into "cDstFile" from source image file "cSrcFile"

saludos

Marcelo
Marcelo Via Giglio
 
Posts: 1051
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Load, show in dialog, interactively crop and save cropped

Postby codemaker » Thu Jun 28, 2012 4:23 pm

Thank you,

The main problem with cropping is to load the image, make some square with mouse and then cropp the part of the image, in selected square boundaries.
This is the main step I am looking for. I need exact view what will be cropped.

BTW: the sample you showed, crops JPG files, is there also the function to cropp BMP files?

Boris
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Load, show in dialog, interactively crop and save cropped

Postby ukoenig » Thu Jun 28, 2012 5:09 pm

Boris,
You can crop any Image-format.

The tool, I have created last year.
Starting with a new update, I got some new ideas.

1. a new button < crop > that just crops the image to the defined Name
the new name is the original + _1 like Olga.jpg to Olga_1.jpg
with the other button You can save the new image to a different place.
2. Now the < Reset-button > closes the crop-dialog and restores the original

Image

3. Mouseclick top / left and bottom / right defines the crop-area

Image

4. Now the < crop-button > creates the new image and shows it on screen.

Image

We still need a solution to paint the box (yellow frame), after the second mouseclick ( bottom / right ) to show the area !!!
Any ideas are welcome.


@ 5, 5 IMAGE oBmp FILENAME cWorkFile OF oWnd ;
SIZE nSWidth - 30, nSHeight - 130 PIXEL SCROLL
oBmp:bLClicked := {|nRow,nCol| ( nCounter ++, GET_VALUES(nRow,nCol) ) }

< nCounter > counts the mouseclick. Value 2 means < bottom / right >
GET_VALUES(nRow,nCol) shows the crop-area top, left, bottom, right
next we must use theses values to draw the box !!!!

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Load, show in dialog, interactively crop and save cropped

Postby codemaker » Thu Jun 28, 2012 6:07 pm

The version of program I have, seems doesn't take the coordinates provided and prints the image back to disk as it wqas originally. Doesn't crop it :(
Can you check the ZIP file you provided, which was the only one to download. Maybe there is some bug?


It would be even better if we can draw some square on the image and remember the coordinates. Then we should be able to "catch" this square/rectangle and resize it, while remembering the coordinates.

Another variant would be to create a rectangle on the image and then, having 4 buttons we can "spin" up and down values, which will automatically resize the rectangle on the image. We should have something like Trectangle() class, or something...
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Load, show in dialog, interactively crop and save cropped

Postby ukoenig » Thu Jun 28, 2012 6:50 pm

Boris,

I got it working and will created a new Zip for Download

http://www.pflegeplus.com/fw_downloads/imgcrop2.zip

Image

Very simple :
1. select < crop > from the mainwindow
2. click < top / left > and < bottom / right >
3. the white box shows the defined area, If You don't like, select < Reset >
4. select < crop > from the sub-dialog

STATIC FUNCTION DRAWBOX( nTOP, nLEFT, hDC1, nRIGHT, nBOTTOM, nPEN, nCOLOR )
LOCAL hPen := CREATEPEN( PS_SOLID, nPEN, nColor )
LOCAL hOldPen := SELECTOBJECT( hDC1, hPen )

MOVETO( hDC1, nLEFT, nTOP )

LINETO( hDC1, nRIGHT, nTOP )
LINETO( hDC1, nRIGHT, nBOTTOM )
LINETO( hDC1, nLEFT, nBOTTOM )
LINETO( hDC1, nLEFT, nTOP )

SELECTOBJECT( hDC1, hOldPen )
DELETEOBJECT( hPen )

RETURN NIL


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Load, show in dialog, interactively crop and save cropped

Postby codemaker » Thu Jun 28, 2012 8:15 pm

Uwe,
looks excellent!
Much better with this rectangle

Hovewer, just cannot figure out, why I am not able to crop anything?? :(

1. Select some image
2. Hit "Crop" on lower bar
3. Click with mouse first for "top-left" and second for "bottom-right" (the 4 GET fields show coordinates)
4. Click "Crop" on the right - the original image saved
5. Click "Save" on the right - the original image saved

Like the GET fields contains no new (cropped) coordinates.
Or the saving part, does not use cropped region, but the whole image.

This what you made is exactly what I need, but I cannot crop :(

Please, help me to crop the part of one image successfuly....

Thanks for code
Boris
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 39 guests