Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在不拉伸图像的情况下调整图像大小?_C#_Bitmap_System.drawing - Fatal编程技术网

C# 如何在不拉伸图像的情况下调整图像大小?

C# 如何在不拉伸图像的情况下调整图像大小?,c#,bitmap,system.drawing,C#,Bitmap,System.drawing,我试图在不拉伸图像的情况下,在C#中调整图像(位图)的大小 假设图像为100x100像素 我希望将其设置为100x110像素,并在添加额外像素的图像底部留一个白色间隙 我已经这样做了,但是找不到指定像素格式的方法。我需要对它进行8bpappindexed。我已经附上了一个例子来显示之前和之后的图像 这是我到目前为止的代码 string visit2 = "C:\\users\\moorez\\desktop\\visit2.bmp"; Bitmap orig = new Bitmap(vi

我试图在不拉伸图像的情况下,在C#中调整图像(位图)的大小

假设图像为
100x100
像素

我希望将其设置为
100x110
像素,并在添加额外像素的图像底部留一个白色间隙

我已经这样做了,但是找不到指定像素格式的方法。我需要对它进行
8bpappindexed
。我已经附上了一个例子来显示之前和之后的图像

这是我到目前为止的代码

string visit2 = "C:\\users\\moorez\\desktop\\visit2.bmp";

Bitmap orig = new Bitmap(visit2);
int width = orig.Width;
int height = orig.Height;
int newHeight = height + 2;
Bitmap newImage = orig.Clone(new Rectangle(0, 0, width, height), System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
newImage.Save("C:\\users\\moorez\\desktop\\visit3.bmp");

Bitmap test = new Bitmap(width, newHeight);
Graphics g = Graphics.FromImage(test);
g.DrawImage(newImage, new Point(0, 0));
test.Save("C:\\users\\moorez\\desktop\\visit4.bmp");
你可以试试这个

Bitmap bmp = new Bitmap(newImage.Width, newHeight);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
g.DrawImageUnscaled(newImage, 0, 0, newImage.Width, newHeight);
bmp.Save(@"C:\\users\\moorez\\desktop\\visit3.bmp", ImageFormat.Jpeg);

请出示你的密码。尚不清楚您使用什么方法创建位图,以及如何在位图上绘制另一个位图来帮助您。GDI+不支持绘制到8bpp图像中。这是非常不平凡的,将颜色深度从1600万减少到256色会留下许多令人不快的瑕疵。你需要另一个图形库,我想一个RGE可以做到。最好不要麻烦,20年前,当640 KB的内存足够时,8bpp很重要。@HansPassant我不想使用这种格式,但还有另一个程序将在需要它的映像上运行。不过谢谢,我会调查一个问题。我希望用户能够记录这些“其他程序”。所以我们知道要远离他们。@HansPassant如果这是一个附带项目,我会的,但这是为了工作,该项目不向公众开放。对不起,“我需要为它编制索引”