imageview update/refresh
Posted
#1
(In Topic #1540)
Regular

I've been struggling with this for about a week I've read the relevant parts of the wiki and some chapters of a gambas online book, but I still cant work out what Im doing wrong.
I have one form with an imageview on it. I load and display an image, then I directly edit the pixels in the image to put a cross in the position where I double click on the image. All good so far…
I've stored the points where the crosses need to be drawn in an array.
I detect a CTRL+Z 'undo'
I then copy an unedited copy of the image into the working copy, and to an inageview.update(workingcopy)
I then re draw all but the last cross.
The problem I have is only the first undo works, sometimes none work, but I can't work out what I'm doing wrong, I've used breakpoints and debug statements to help work out what is going wrong and can see that the ImageView doesn't appear to be refreshing with the clean image,
Code (gambas)
- ' Gambas class file
- ''This is the main form
- workingCopyImage = originalImage 'copy originalImage
- pointIndex = 0
- capturePoint()
- undo()
- ''store the position of the mouse when doubleclicked in Coord[,]
- drawCross(Coord[pointindex, 0], Coord[pointindex, 1])
- pointIndex += 1
- Debug "Undo"
- Debug "nothing to undo"
- Return 'exit sub if there's nothing to do
- Debug "Copy original image into working copy - so all the crosses are removed"
- workingCopyImage = originalImage
- Debug "let's undo something"
- pointIndex -= 1 'reduce point index by 1
- 'clear points from image
- Debug "load new image into imageview1"
- imageview1.update(workingCopyImage)' Refresh the view, but don't redraw *everything*.
- drawCross(Coord[f, 0], Coord[f, 1]) ' Redraw the existing crosses.
- ''drawCross Draws a cross in the screen centered at (x,y)
- ''draws a small cross at the x,y coordinates
- Debug "Draw cross directly on working copy image"
- workingCopyImage[x - 3 + f, y - 3 + n] = 16646144 'red
- 'get the zoom and scroll poistions
- z = imageView1.Zoom
- sx = imageview1.ScrollX
- sy = imageview1.ScrollY
- imageview1.Update()
- 'set the zoom and scroll positions -so the image updates but doesn't reset
- imageview1.Zoom = z
- imageview1.ScrollX = sx
- imageview1.ScrollY = sy
Any help really appreciated - I did think it might be a wayland quirk, but the same happens if I use X11.
Posted
Guru

This line is not correct, (the code does not match the comment)…
Code (gambas)
- workingCopyImage = originalImage 'copy originalImage
try like this..
Code (gambas)
and do the same wherever you need a "Copy" of a Picture/Image not a pointer to it.
Posted
Guru

Posted
Regular

BruceSteers said
With the above code workingCopyImage becomes a pointer to originalImage not a copy of it
try like this..Code (gambas)
and do the same wherever you need a "Copy" of a Picture/Image not a pointer to it.
Thank you so much for the correcting and the explanation
Posted
Regular

cogier said
Have you thought of saving the image each time a cross is added so that you can undo/redo by just changing the imageview image?
I did, but it didn't feel like good practice to be using file storage like this
Posted
Guru

(I have not tested this so you might need to tweak it)
Code (gambas)
- Debug "Undo"
- Debug "nothing to undo"
- Return 'exit sub if there's nothing to do
- Debug "Copy original image area at coords directly onto the imageview image"
- Debug "let's undo something"
- pointIndex -= 1 'reduce point index by 1
- X = Coord[pointIndex, 0] - 3
- Y = Coord[pointIndex, 1] - 3
- Paint.DrawImage(originalImage.Copy(X, Y, 6, 6), X, Y, 6, 6) ' Draw a 6x6 square at X, Y copied from the original.
- Paint.End ' finish editing
- ImageView1.Refresh ' maybe you don't need this?
Ps. another tip. In your Key event you check to see if key.code = 90
It is bad practice to use code values directly because key codes can be different for QT and GTK.
you should check if Key.Text = "z" or if there is no text (like some special keys) check the Key array If Key.Code = Key["Z"]
then it will work for both QT and GTK.
Have fun
Posted
Regular

1 guest and 0 members have just viewed this.


