-1

Hi im trying to overlap 2 images with transparent backgrounds. i heard i can use the OnPaint method to do this so i tried

    protected override void OnPaint(PaintEventArgs e)
    {
        System.Drawing.Graphics obj;
        obj = this.CreateGraphics();
        int x = 0;
        int y = 0;
        System.Drawing.Point point = new Point(x, y);
        obj.Clear(Color.White);
        obj.DrawImage(System.Drawing.Image.FromFile(@"C:\Users\William\Documents\Sprites\Player\Male\Default\Light.png"), point);
        obj.Dispose();
    }

but im not sure how to draw another one on top of it and if it will be transparent, any help is appriciated

Jason
  • 233
  • 4
  • 17
  • 1
    Replace `obj = this.CreateGraphics();` by `obj = e.Grpahics` and your chances get a lot better! Also don't dispose it now! Drawing another image on top works __just like drawing the 1st one__! Also: In the OnPaint or Paint events you (usually) don't need/want to clear the surface.. – TaW Mar 20 '16 at 18:51
  • it gave me an error but the old one still works – Jason Mar 20 '16 at 18:55
  • What error did you get?? Are you still disposing of the `e.Graphics` you didn't and shouldn't and can't create? – TaW Mar 20 '16 at 18:55

1 Answers1

0

Just draw the other picture on top of the first one, like so:

e.Graphics.DrawImage(Image.FromFile(@"C:\Picture1.png"), point);
e.Graphics.DrawImage(Image.FromFile(@"C:\Picture2WithTransparentBackground.png"), point);
Ulf Kristiansen
  • 1,571
  • 3
  • 22
  • 34
  • Still, you should do away with the `this.CreateGraphics` and __NEVER__ use it again! – TaW Mar 20 '16 at 18:56