位图在面板中未正确对齐 [英] Bitmap not Aligning Properly in Panel

查看:28
本文介绍了位图在面板中未正确对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 Google 上搜索了一段时间,但似乎无法找到解决我问题的方法.

I've been looking around on Google for quite some time and cannot seem to find a solution to my problem.

问题在于将位图绘制到面板上.出于某种奇怪的原因,整个位图似乎向面板的左上角偏移.这使得构建地图时变得混乱.作为额外的注意,位图是在比自身大的面板上绘制的.(例如 bitmap.dimensions == 64x64 和 panel.dimensions == 512x512).

The problem is with painting a bitmap onto a panel. For some strange reason the entire bitmap seems to have an offset towards the upper-left of the panel.Which makes it confusing when building the map. As an extra note the bitmap was being painted on a panel larger than itself. (e.g. bitmap.dimensions == 64x64 and panel.dimensions == 512x512).

    private void redrawCityPanel()
    {
        Image cityImage = this.cityBitmap;

        Graphics panel_CityGraphics = this.panel_City.CreateGraphics();
        panel_CityGraphics.Clear(this.panel_City.BackColor);
        panel_CityGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
        panel_CityGraphics.DrawImage(cityImage, panel_City.DisplayRectangle);
    }

抱歉造成混乱.我会发布图片,但我还没有获得足够的积分.

Sorry about the confusion. I would post images but I haven't earned enough points.

推荐答案

我需要做的就是设置像素偏移模式.

All I needed to do was set the pixel offset mode.

private void redrawCityPanel()
{
    Image cityImage = this.cityBitmap;

    Graphics panel_CityGraphics = this.panel_City.CreateGraphics();
    panel_CityGraphics.Clear(this.panel_City.BackColor);
    panel_CityGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;

    panel_CityGraphics.PixelOffsetMode = PixelOffsetMode.Half; //Added

    panel_CityGraphics.DrawImage(cityImage, panel_City.DisplayRectangle);
}

这篇关于位图在面板中未正确对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆