What's a simple way to update a Bitmap with another Bitmap given a top left corner?

StackOverflow https://stackoverflow.com/questions/23320753

  •  10-07-2023
  •  | 
  •  

Question

I'm writing a Object method that is passed in a Bitmap and copies into the Object's own bitmap at the given top left corner parameter.

    public void updateWithSprite(int x, int y, Sprite sprite)
    {            
        //some code here. 

    }

What's a simple way to do this?

Était-ce utile?

La solution

Graphics.DrawImage will let you do this:

    public void updateWithSprite(int x, int y, Sprite sprite)
    {

        Bitmap sprBitmap = sprite.getBitmap();
        Graphics g = Graphics.FromImage(this.bitmap);
        g.DrawImage(sprBitmap, x, y, sprBitmap.Width, sprBitmap.Height);
        g.Dispose();
    }

See also: http://msdn.microsoft.com/en-us/library/aa457087.aspx

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top