locked
How to implement "eraser" function in Direct2D?

    Question

  • Hi,

    I'm developing a direct2D app, and this app let user draw something with direct2d brush.

    but how to implement eraser ? I found 'Clear' api, but it will clear all render target.

    I totally can't figure out this, plz help!

    Thanks!

    Thursday, July 25, 2013 5:02 PM

Answers

  • Hi,

    I have done it with GDI in c++ before,and there is nothing ready-made for me to use.

    I do it just like it. Store all pixel of points in draw area into a array[][](point_x=rows,point_y=columns).Every point has it's pixel,then i just keep my mind on point and when a specific area is going to be erased i just go to loop to find the specific points and change it pixel.Of course,it is only a method to process similar problem.I hope it will give you some idears to solve it.

    good luck!

    • Marked as answer by gogoqaz Wednesday, July 31, 2013 2:30 PM
    Friday, July 26, 2013 7:36 AM
    Moderator

All replies

  • Is the goal to remove entire strokes/geometries, or to "erase" specific areas the user clicks on similar to how the Paint app works?

    The easiest approach may be to simply change the active Direct2D brush so that it's painting whatever the background color is - that will make it appear to be erasing.

    If you instead want to erase whole strokes at once, you can just re-render the whole scene without the "erased" lines/geometries.

    Thursday, July 25, 2013 6:04 PM
  • Dear Jesse,

    Thank for reply!

    Yes, I want to erase specific areas just like MS Paint's eraser does.

    But my problem is the background color is transparent, so I can't change bursh's color setting to background color to 'erase' it.

    The way I only can do is to control the pixel data to 0 for the specific areas that I want to erase?

    Thanks!!


    • Edited by gogoqaz Friday, July 26, 2013 2:05 AM edit
    Friday, July 26, 2013 2:03 AM
  • Hi,

    I have done it with GDI in c++ before,and there is nothing ready-made for me to use.

    I do it just like it. Store all pixel of points in draw area into a array[][](point_x=rows,point_y=columns).Every point has it's pixel,then i just keep my mind on point and when a specific area is going to be erased i just go to loop to find the specific points and change it pixel.Of course,it is only a method to process similar problem.I hope it will give you some idears to solve it.

    good luck!

    • Marked as answer by gogoqaz Wednesday, July 31, 2013 2:30 PM
    Friday, July 26, 2013 7:36 AM
    Moderator
  • Hi,gogoqaz

    How's it going? Do you have any updates about the previous issue? Please reply to let us know if this issue has been resolved. If so, I can mark this thread as answer.

    Wednesday, July 31, 2013 7:44 AM
    Moderator
  • Hi gogopaz,

    Direct2D does not support the notion of "removing" primitive from the scene because it does not retain content that has been drawn to the scene. Instead the app can retain all the current primitives and keep track of what has been previously erased. It can then "not drawing" the erased primitive on the next frame. The simplified inking sample here http://code.msdn.microsoft.com/windowsapps/Input-simplified-ink-sample-11614bbf/sourcecode? fileId=50994&pathId=983762219 illustrates the idea through the use of the ink recognizer as identifier of ink stroke.

    Worachai Chaoweeraprasit

    Microsoft Corporation.

    Friday, September 13, 2013 10:09 PM