开发者

Drawing specific rectangle of a Bitmap into another Bitmap

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜