繁体   English   中英

C#graphics.drawImage()裁剪我的图像

[英]C# graphics.drawImage() crops my Image

我正在尝试将图像放大。 但是内部图像在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);
    }
}

提前致谢

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

像这样尝试:

Bitmap im = new Bitmap("D:\\Steffen\\New folder\\I1\\I1\\" + filename + ".png");
im.SetResolution(96F, 96F);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM