Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I'm trying to make a drawing board tha support adding shapes and images. for pencil I use this code and I don't think that there is a way to erase it but just trying:
VB
            Dim lin As New Line
            lin.Stroke = New SolidColorBrush(Color.FromArgb(100, 255, 0, 0))
            lin.StrokeThickness = 5
'lastpnt is the LastPoint added to continue the drawing and it will be null on mouse_up Event
            If Not lastpnt = Nothing Then
                lin.X1 = lastpnt.X
                lin.Y1 = lastpnt.Y
                lin.X2 = position.X
                lin.Y2 = position.Y
                lastpnt.X = position.X
                lastpnt.Y = position.Y
            Else
                lin.X1 = position.X
                lin.Y1 = position.Y
                lin.X2 = position.X
                lin.Y2 = position.Y
                lastpnt.X = position.X
                lastpnt.Y = position.Y
            End If
            Canvas1.Children.Add(lin)


I can make the eraser the same as background color but what if the back color was transparent or was an image ????
I will now read the 'InkCanvas' source code trying to find another way to draw and erase.

Note : I didn't use inkcanvas due to no support adding images above the ink drawing and then drawing on image (I don't know how to explain but its like ink and Images zOrder)
Posted
Updated 12-Nov-19 23:19pm

Here is the thing: Canvas is a parent element for collection of UIElements accessible as the property Children:
http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.children.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.uielementcollection.aspx[^].

So, just removed some child element from the collection; and it will be immediately "erased". There is nothing else you should do.

—SA
 
Share this answer
 
Comments
Abed AlSayed 21-Jan-13 17:19pm    
you are right that's the only way. But what if I convert the UIElements to a bitmap? What is the possible way to remove pixels?
Sergey Alexandrovich Kryukov 21-Jan-13 17:42pm    
It's quite possible. I recently answered on how to write to such bitmap. Erasing... more complex, needs thinking, but why?
—SA
Abed AlSayed 21-Jan-13 18:44pm    
I will search on Google for the 13th time :(
do you anything about converting a rectangular area of an image to transparent?
Maybe I should return to WinForms, then I will not bother people anymore with these questions :'(
Sergey Alexandrovich Kryukov 21-Jan-13 19:07pm    
I would encourage you to use WPF, for the editor, by a number of different reasons, but of course you are the one who decides. Everything is solvable, in terms of graphics — everything; and performance is much less of a problem, and there is no or much less potential dependency of Windows legacy.

"Converting to transparent"... what do you mean? This is just one of the cases partial cases of image transform. "Non-transparent" is just transparent with maximum opacity, that is, maximum value in Alpha channel.

If you have some difficulty with it, as another question, after all...

—SA
If you maintain a history of actions taken, then you can recreate the image at any point in the history thereby "deleting" an item by simply removing it from the history and then rebuilding the image from the existing historical items.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Jan-13 16:38pm    
What you say is applicable to Forms. I think you are missing the fact that Canvas is a vector UI element, it is a parent for child element put on it. So, all you need is just to delete one of the children... Order of actions taken, even if you have it (for "undo", for example) is in fact irrelevant...
—SA
Sergey Alexandrovich Kryukov 21-Jan-13 16:41pm    
I answered this question; please see.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900