I have found many useful links on the forum advising how to modify my old code that referenced the Canvas.Graphics object outside of the Paint event and have settled on creating a background buffer image, doing all the drawing to its graphics object and then calling Invalidate().
Now in the Paint event I have the following code which works well:
If bufferPic <> Nil then
g.DrawPicture(bufferPic, 0, 0)
End If
I also need to optimize drawing by only invalidating portions of the canvas and so call Invalidate() using coorindates and width/height parameters:
Invalidate(10, 10, 100, 100, False)
So, firstly, would the code below in the Paint event correctly update only the portion of the canvas I have stated in the Invalidate call?
Dim i, count, X, Y, aWidth, aHeight As Integer
count = Ubound(areas)
If count < 0 then
g.DrawPicture(bufferPic, 0, 0)
Else
For i = 0 to count
X = areas(i).X
Y = areas(i).Y
aWidth = areas(i).Width
aHeight = areas(i).Height
g.DrawPicture(bufferPic, X, Y, aWidth, aHeight, X, Y, aWidth, aHeight)
Next
End If
Secondly, can anyone tell me the most efficient/optimized way of copying a picture object using pure Xojo code and also a third-party plugin if required?
I have Einhugar’s PictureEffects plugin but don’t think it has a copy feature (unless I am mistaken) and I know some people have mentioned MBS plugins for this kind of task. It is also important to be able to preserve the transparency/alpha channel during the copy.
Once I know the best solution to this I intend to add this method to a global module so I can frequently call it rather than hard-coding the same Graphics.DrawPicture() calls each time in multiple places.
Thanks.