【问题标题】:Drawing specific rectangle of a Bitmap into another Bitmap将位图的特定矩形绘制到另一个位图中
【发布时间】:2011-09-06 16:41:32
【问题描述】:

我有一个很大的位图——我的游戏的整个 MAP。但是,我想从中绘制一个特定的矩形 - 而不是整个地图,因此它可以适合游戏的屏幕。
这是我的方法:

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

}

在同一个类中,我有一个名为Size 的字段,称为viewSize,它给出了游戏屏幕的大小。我还有另一个字段Bitmap,也叫Map

因此,方法drawMap 应该将Map 中的特定location 与大小viewSize 绘制成g

提前致谢。

编辑: 我已经通过引用传递了location,所以性能更好

【问题讨论】:

    标签: c# graphics gdi+


    【解决方案1】:

    试试这个:

    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);
    }
    

    【讨论】:

    • 我们已经借鉴了g1。我想要 g 参数上的绘图
    • @Mr.DDD:你这样编辑我的帖子!!如果您想在g 上绘图,只需注释前两行并使用g 代替g1
    • @Mr.DDD:我恢复了我的帖子。这是你需要的吗? :D
    猜你喜欢
    • 2015-11-17
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多