Jump to content

How to create an eraser tool?


glacialfury
 Share

Recommended Posts

I'm trying to create a simple drawing program with layers. The default bottom layer is a grid that can be shown or not shown. The drawing must occur over the grid (it's used only for guidelines), so it needs to be on the bottom.

The problem is, my current method of erasing is to use the background color and draw over it. This effectively draws a white line, which obscures bits of the grid. I've tried drawing with "Transparent" as the color, but then nothing shows up at all.

How do you truly create an eraser effect, which will remove the previous drawing on a given layer without obscuring the layers below?

Any tips or alternate methods are greatly appreciated.

Link to comment
Share on other sites

Paint.NET already has an eraser tool... why would you need to create one?

This forum is for Paint.NET general coding/programming discussion. We can not typically help you develop other programs in there.

But, you can download the Paint.NET source code and look for yourself how the eraser tool works.

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

True, it is a separate project, for personal learning. However, Paint.NET is unique on the web as the only advanced painting application that is opensource and uses .NET. I have downloaded the source code, but it is vast in its scope and although well-organized, does not reveal its secrets to amateur programmers who may be interested in an isolated portion and are unfamiliar with large, complex projects.

I would be delighted to research the code further, but would certainly appreciate guidance as to where to begin looking.

I apologize for detracting from the main purpose of this forum. Please remove the thread if you feel it is inappropriate.

Link to comment
Share on other sites

Hi glacialfury,

I had a look recently at how layers are rendered in PDN and although by no means an expert I have perhaps delved a little deeper than you and may provide some insight. First I must point out that the software is not that large and although it uses some advanced techniques it is amazingly simple to fathom once you understand the overall design. Of course, it could stand some high-level design documentation for the many people who appear to be interested in studying it.

But back to your question ... First you must understand that each layer is stored separately. (Each Document contains a LayerList which is an ArrayList of Layers. Currently all Layers are of the same derived type BitmapLayer. A BitmapLayer contains a Surface which contains the actual pixels of the layer.)

When you use the eraser you are simply putting transparent pixels onto the active layer so that whatever is below (a layer below or the background) shows through. When you erase (or draw something) you only change the active layer which is immediately combined with the other layers to be rendered on the screen. (The rendering of a layer occurs in BitmapLayer.RenderImpl which is called for each layer from Document.Render. After that other "decorations" not part of the actual design are rendered like nubs, selection, grid etc.)

I hope this helps.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...