【发布时间】:2013-07-17 03:19:33
【问题描述】:
我正在尝试将图像放在更大的图像上。但是内部图像在 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);
}
}
提前致谢
【问题讨论】:
-
无复制。顺便说一句,如果
sizeX == sizeY,您没有size的值。 -
谢谢,但它仍然不会影响问题,因为我正在测试非二次图像
-
第一个位图'im'有 365x500 像素,24 位深度
标签: c# .net visual-studio-2010 drawimage