开发者

Drawing specific rectangle of a Bitmap into another Bitmap

开发者 https://www.devze.com 2023-04-03 01:41 出处:网络
I have a big Bitmap in size - the entire MAP of my game. However, I want to draw a specific rectangle from it - not the entire map, so it can fit on game\'s screen.

I have a big Bitmap in size - the entire MAP of my game. However, I want to draw a specific rectangle from it - not the entire map, so it can fit on game's screen.

Here is my method:

private void drawMap(Graphics g, ref Point location)
{

}

In the same class, I have a field of Size, called viewSize which gives the size of the game's screen. I have another field of Bitmap, called Map, too.

So, method drawMap shoul开发者_如何学JAVAd draw the specific location in Map with size viewSize into g.

Thanks in advance.

EDIT: I have made the location passed by reference so the performance is better


Try this:

private void drawMap(Graphics g, ref Point location)
{
    // Draw the specified section of the source bitmap to the new one
    g.DrawImage(Map, location.X, location.Y, viewSize.Width, viewSize.Height);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号