0

我正在尝试将图像放在更大的图像上。但是内部图像在 drawImage() 之后被裁剪。这是我的代码:

Bitmap im = new Bitmap("D:\\Steffen\\New folder\\I1\\I1\\" + filename + ".png");
int sizeX = im.Width;
int sizeY = im.Height;
int size = 0;
bool isWidth = false;
if (sizeX > sizeY) 
{ 
    size = sizeX; isWidth = true; 
}
else if(sizeY > sizeX)
{ 
    size = sizeY; isWidth = false; 
}

filename = filename + "New";
Bitmap bg = new Bitmap(size,size);
SolidBrush brush = new SolidBrush(Color.Aqua);

using (Graphics g = Graphics.FromImage(bg))
{
    g.FillRectangle(brush, 0, 0, size, size);
    if (isWidth==true)
    {
        g.DrawImage(im, 0, (size - sizeY) / 2);
    }
    else if(isWidth==false)
    {
        g.DrawImage(im, (size-sizeX)/2, 0);
    }
}

提前致谢

4

1 回答 1

0

我的猜测是图像的分辨率是问题:

试试这样:

Bitmap im = new Bitmap("D:\\Steffen\\New folder\\I1\\I1\\" + filename + ".png");
im.SetResolution(96F, 96F);
于 2013-07-16T19:19:33.573 回答