# [.net] .Net Drawing2D Layers ala Photoshop or Gimp

## Recommended Posts

Hi, I have started using .Nets GDI drawing library, and I was wondering if its possible to draw things to a graphics object in layers. Photoshop and Gimp allow drawing to various layers and then combining them into a single layer/image, and I want to know if anything similar in .Net is supported? I am looking for the ability to draw various shapes etc onto a given layer, and then switch that layer on or off. For example, imagine I want to draw a dynamic map. It has a JPG image as the background, a second layer with place names, and then a third layer showing road routes. I want the user to be able to toggle the place names on or off. Any tips / advice appreciated.

##### Share on other sites
Make each layer a transparent image, drawn onto separately, and then just use DrawImage() to draw each visible layer in turn.

##### Share on other sites
Quote:
 Original post by Bob JanovaMake each layer a transparent image, drawn onto separately, and then just use DrawImage() to draw each visible layer in turn.

Hi Bob thanks for the reply.

When you say 'transparent image', do you mean an actual graphics object, or a bitmap object ...or both?

##### Share on other sites
I don't know if this will be helpful to you or not (because I didn't document how any of this actually works), but here is one such approach...

        /* Layer Stuff. */        Bitmap[] TheLayers = new Bitmap[MAX_LAYERS];        TheLayers[0] = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);        TheLayers[1] = new Bitmap(Width2, Height2, PixelFormat.Format32bppArgb);        TheLayers[2] = new Bitmap(Width3, Height3, PixelFormat.Format32bppArgb);        /* Draw some pixels. */        TheLayers[1].SetPixel(5, 2, Color.FromArgb(40, 53, 53, 52));        /* Draw the layers onto the screen. */        Graphics MyScreen = Graphics.FromImage(this.BackgroundImage);        for (int TheLoop = 0; TheLoop < MAX_LAYERS; TheLoop++)            MyScreen.DrawImage(TheLayers[TheLoop], 0, 0);        /* This might be needed... */        this.Invalidate();

##### Share on other sites
Cool, thanks for the example Thevenin :)

##### Share on other sites
Thevenin: yeah, that's pretty much what I had in mind. By 'image' I meant 'System.Drawing.Image', of which Bitmap is the sane answer although some sort of vector canvas would be cool too. (Aside: is there such a thing in the Framework? An image class that remembers all the vector primitives you've drawn to it?) The only question is whether you can clear an image (or Bitmap) to transparent so layers don't interfere with each other where they shouldn't. I think you can, but I haven't actually tried a solution like this myself.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627636
• Total Posts
2978331

• 10
• 12
• 22
• 13
• 33