May 16, 2024, 12:36:23 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Simple Image Editor

Started by LarryMc, July 23, 2008, 01:32:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

Attached is all the files needed to compile my simple image editor that I created for use in my genealogy work.

This is a subset of that project.

Originally this worked but when cropping an image everything that was being cropped had to be visible. This meant the result of a cropping couldn't be bigger than the size of my window.

I wanted to change that so that I could start a cropping rubberband at one point and then be able to scroll the image over to set the endpoint of the rubberband.

This would result in a cropped image that was larger than my window with the appropriate scrollbars.

I haven't had much luck and find my attention span is getting real short.

I'm posting my source in case there is anyone who is interested in seeing if they can figure everything out for me.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

July 23, 2008, 04:39:17 PM #1 Last Edit: July 24, 2008, 10:34:20 AM by sapero
When you hold left button down and move the mouse outside winImage, the image will be scrolled.
I've added SetCapture() in @IDLBUTTONDOWN  handler, to tell the system that it should send mouse notifications to winImage, even if the cursor is outside your window. Then in @IDMOUSEMOVE you can detect if the cursor is inside or outside client area, and scroll the image as needed. This is handled in additional winImageFollowCursor() function.

See in (updated v2) attachment for details.

LarryMc

Sapero,
  The rectangle and the scrolling appears to work great now.

Problem is that it doesn't crop what I put the box around and/or the program crashes.

Could you possibly look at that?

Attached is the image I was using.  It's a picture of my oldest son and me.
(BTW I'm 6'2" and weight 280. My son in 6"7" and weighs 430) ;D

Larry

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

Done. The problem was in sub cropimage(). My mistake was to validate xend/yend in @idlbuttonup.
Attachment updated.

LarryMc

Sapero,
I don't understand what is happening; your update still doesn't work for me.

If I start the crop box just to the left-top of my son's face and drag to inclose all of my head then button up all of my head is not captured.

If I start the crop box just to the left-top of my son's head and drag down and right to catch all his head and all his tie then button up I only get a little of his tie.

If I try to select the whole image with the crop box I wind up with an image that is what was originally display minus the width of the scrollbars.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

Sorry, I did not check all cropping combinations.
You'll need two additional variables (global for B100_Main module) to store starting crop position including position of the scrollbar:
int xstart_raw
int ystart_raw

$main

In winImage handler:   case @idlbuttondn
xstart=@mousex:ystart=@mousey:buttondn=1
drawrectangle=1

' save real coordinates
xstart_raw = xstart + getscrollpos(winImage,-1)
ystart_raw = ystart + getscrollpos(winImage,-2)

SetCapture(winImage.hwnd)

  case @idlbuttonup

ReleaseCapture()

buttondn=0:drag=0
if (selection=1)
ShowHideCropRectangle()

' set start coordinates to real coordinates
xstart = xstart_raw
ystart = ystart_raw
' same with end coordinates
xend += getscrollpos(winImage,-1)
yend += getscrollpos(winImage,-2)

gosub cropimage
selection=0
SetCursor winImage,@CSCustom,LoadCursorA(0,IDC_ARROW)
endif


Then in cropimage function do not include scrollbar positions: if (xend>xmax) then xend=xmax
if (yend>ymax) then yend=ymax

if (xstart < 0) then xstart = 0
if (ystart < 0) then ystart = 0
iluCrop(xstart,ymax-yend,0,xend-xstart,yend-ystart,0)

LarryMc

Sapero,
It's awful close now but no cigar.

Select a box as wide as my son's head from as close to the top as possible all the way down to the bottom of his tie.
Scroll to the bottom of the result and look real close at the bottom of his tie; there are several pixel rows that are repeated.


Do the same thing again and start just above his eyeglasses and the problem at the bottom is easier to see.

The same sort of thing is happening on the right edge too.

It appears that the width of the scroll bars is throwing something off.

Hey, I really do appreciate you fooling with this.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

:) You need to remove scrollbars in updateimage() before calling getclientsize:
sub updateimage()
int h1,w1, ImageH, ImageW
uint hdc

setscrollrange winImage,-1,0,0
setscrollrange winImage,-2,0,0
getclientsize winImage,x,y,w1,h1

LarryMc

I don't see how I can do that because I need w1 and h1 before I do the setscroll range.

Larry


   
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

July 24, 2008, 12:24:36 PM #9 Last Edit: July 24, 2008, 12:26:50 PM by sapero
Larry, when you open the first image, there is no scrollbar, and the getclientsize returns the full client area. After loading a large enough image, both scrollbars are visible.
Now you start cropping, and when finished updateimage is called (with both scrollbars), so the getclientsize function in updateimage() returns smaller area as for the first image.
For this reason your calculated scrollbar range is wider than required.

LarryMc

Sapero

Based upon what you just posted I did some looking and experimenting.

When I load an image I offset it 28 pixels so that my menu buttons aren't covered up in the window.
I do that with setsize 28,28,blah, blah

So,
in the updateimage() I changed 2 lines of code by adding -28 to them to:if ImageW - w1-28 < 0 thenandif ImageH - h1-28 < 0 thenand left everything else the same including the getclientsize that is at the beginning of the routine.

Everything I've test so far appears to be working fine.

There is absolutely no way I could have ever got this working without your help.
As always, "you're the man" and thanks a million.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

ops
Everything looks and works great when I load an image larger than the window.

When I load an image smaller than the window it has one little flaw.

When I am creating a crop box, as I drag the lower right corner the whole image is distorted with a grid like pattern.  You can see it when you slightly move the mouse.
However, when you button up the cropped image is the correct size and has no distortion.
I can live with that.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

I cannot get it. Could you provide image width/height and cursor starting coordinates?

Bruce Peaslee

Quote from: Larry McCaughn on July 23, 2008, 06:37:33 PM
Attached is the image I was using.  It's a picture of my oldest son and me.
(BTW I'm 6'2" and weight 280. My son in 6"7" and weighs 430) ;D

Larry



Texans. Gotta love 'em.  :D
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

LarryMc

Now this is AFTER I added the -28 as I posted above(which fixed the problem with the right and bottom edges of the cropped image.
Attaching my B110.eba

It does it on any image I use that is smaller than my window when I load it.

Sample img attached and it doesn't matter where you start the crop

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Quote from: peaslee on July 24, 2008, 03:23:08 PM
Quote from: Larry McCaughn on July 23, 2008, 06:37:33 PM
Attached is the image I was using.  It's a picture of my oldest son and me.
(BTW I'm 6'2" and weight 280. My son in 6"7" and weighs 430) ;D

Larry



Texans. Gotta love 'em.  :D
Bruce,
I like your response a lot better than the typical " I didn't know they stacked %&@!@ that high" :D

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

July 24, 2008, 04:38:03 PM #16 Last Edit: July 24, 2008, 04:43:33 PM by sapero
Larry, the image is mailformed just after loading it. Try to load image with black on white text, small font. Use same image in png and jpg formats. Png has garbages and jpg is blured, while both images are propertly displayed in windows paint.
When i size the crop rectangle, the image inside this rectangle is 'moving' or better: animating. I did not noticed this on color images.
Maybe you have to set/unset something in IL like forcing ilutConvertToHBitmap to return 24 or 32 bpp bitmap, or better a DIB.

LarryMc

July 24, 2008, 04:43:12 PM #17 Last Edit: July 24, 2008, 04:47:02 PM by Larry McCaughn
I just checked it with a small color image and confirm what you said.  Color works fine.

I'll play around with il and see what I can come up with.

Thanks for spending all this time working on my problems Sapero.

Correction: Small Color images are animated also.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

The animation looking problem on B&W images went away when I remove the @autoscale from the imagewind win style.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

This version works pretty good.

BTW, the bulk of the image manipulation code was done by others from the old ibasic forums.
I put pieces of their code together.
And don't forget all of Sapero's help.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Hi mr.Larry i download and try compile Main.eba and i recive this error:
Compiling...
B100_Main.eba
File: C:\Program Files\EBDev\projects\SimImgEdit\B100_Main.eba (316) Warning: undeclared function 'GetCapture'
File: C:\Program Files\EBDev\projects\SimImgEdit\B100_Main.eba (357) Warning: undeclared function 'SetCapture' - )
File: C:\Program Files\EBDev\projects\SimImgEdit\B100_Main.eba (360) Warning: undeclared function 'ReleaseCapture' - )
C:\Program Files\EBDev\projects\SimImgEdit\B100_Main.eba:315: error: symbol `GetCapture' undefined
C:\Program Files\EBDev\projects\SimImgEdit\B100_Main.eba:357: error: symbol `SetCapture' undefined
C:\Program Files\EBDev\projects\SimImgEdit\B100_Main.eba:360: error: symbol `ReleaseCapture' undefined
C:\Program Files\EBDev\projects\SimImgEdit\B100_Main.eba:533: error: phase error detected at end of assembly.
Error(s) in assembling D:\SimImgEdit\B100_Main.a

LarryMc

Means that they are not in your windows.inc file.
Your windows.inc file might have them aliased with a "_" in front of their names.

find these in the file sie.imports.inc
declare import, SetCapture(int hwnd)
declare import, GetCapture(),int
declare import, ReleaseCapture()
and change to
Quotedeclare import, _SetCapture(int hwnd)
declare import, _GetCapture(),int
declare import, _ReleaseCapture()
and also change in all the locations the functions are called.

See if that works

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

I look in my windows.inc file and here write like  you said:
DECLARE IMPORT, _SetCapture ALIAS SetCapture(hwnd AS INT),INT
and maby is errors becose i use free old version of EB?

aurelCB

Intersting.I folow your instruction from readme and nothing heapend.
But ok this is too big for my poor knowlege about EB.
regards