Sign in to follow this  

[.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 this post

Link to post
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... */

Share this post

Link to post
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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this