Jump to content
  • Advertisement
Sign in to follow this  
Paulus_newbieus

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

This topic is 4274 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!