G.drawimage draws with incorrect size

ⅰ亾dé卋堺 提交于 2019-11-28 14:38:51

You don't set the dpi values. These are honored in DrawImage, so you need to set them with bitmap.SetResolution(dpix, dpiy). When they are different in the images the results will be too. You can get the 'correct' one from the Graphics object g or decide what you want.

Quick fix:

        for (int i = 0; i < images.Count; i++)
        {
            ((Bitmap)images[i]).SetResolution(g.DpiX, g.DpiY);
            g.DrawImage((Bitmap)images[i], new Point(10, (i + 1) * 10 + size));
            Bitmap bmp = (Bitmap)images[i];
            ...
        }

Note that the newly created bitmap uses the screen dpi resolution as its default. If you want to control the dpi you need to set them for list as well!

Also note the I didn't change your code; to simplify the last line should really move to the top of the loop and then bmp be used instead of the array element..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!