C# 还没有工作,我正在尝试调整位图的大小,但它们仍然是1920X1080为什么?

C# 还没有工作,我正在尝试调整位图的大小,但它们仍然是1920X1080为什么?,c#,C#,代码如下: if (Form1.ExtractAutomatic == true) { using (var bitmap = new Bitmap(_width, _height, _width * 3, PixelFormat.Format24bppRgb, pBuffer)) { if (!this.Secondpass)

代码如下:

if (Form1.ExtractAutomatic == true)
            {
                using (var bitmap = new Bitmap(_width, _height, _width * 3, PixelFormat.Format24bppRgb, pBuffer))
                {
                    if (!this.Secondpass)
                    {
                        long[] HistogramValues = Form1.GetHistogram(bitmap);
                        Form1.Histograms.Add(HistogramValues);
                        long t = Form1.GetTopLumAmount(HistogramValues, 1000);
                        Form1.averagesTest.Add(t);

                    }
                    else
                    {

                        if (_frameId > 0)
                        {
                            double t = Form1.averagesTest[_frameId] / 1000.0 - Form1.averagesTest[_frameId - 1] / 1000.0;
                            w.WriteLine("averagesTest >>>  " + t);
                            double tt = framesCounts();
                            if (_frameId == framesCounts())
                            {
                                w.Close();
                            }
                            if (Form1.averagesTest[_frameId] / 1000.0 - Form1.averagesTest[_frameId - 1] / 1000.0 > 0.0) 
                            {
                                count = 6;
                            }

                            if (count > 0)
                            {
                                ResizeBitmap(bitmap, 10, 10);
                                bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
                                bitmap.Save(Path.Combine(_outFolder, _frameId.ToString("D6") + ".bmp"),ImageFormat.Bmp);
                                count --;
                            }
而ResizeBitmap是:

public static Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight)
        {
            Bitmap result = new Bitmap(nWidth, nHeight);
            using (Graphics g = Graphics.FromImage((Image)result))
                g.DrawImage(b, 0, 0, nWidth, nHeight);
            return result;
        }
为什么硬盘上的文件是1920X1080而不是10X10? 为什么储蓄如此缓慢?我认为在这种情况下,将文件保存到硬盘大约2600帧应该很快不

有人能告诉我如何根据我的代码修复它吗

谢谢。

应该是

bitmap = ResizeBitmap(bitmap, 10, 10);

您没有将调整大小的位图分配给任何对象

该方法返回位图,因此需要使用该方法的返回值:

Bitmap newBitmap = ResizeBitmap(bitmap, 10, 10);

答案仍然与此处相同:

在第一个代码示例底部附近使用此选项:

using (Bitmap resized_bmp = ResizeBitmap(bitmap, 10, 10))
{
    resized_bmp.RotateFlip(RotateFlipType.Rotate180FlipX);
    resized_bmp.Save(Path.Combine(_outFolder, _frameId.ToString("D6") + ".bmp"),ImageFormat.Bmp);
    count --;
}

这将使用一个新的
Bitmap
变量(并正确地处理它)来执行保存,正如Tim建议的那样。

I cant make Bitmap=问题是,如果我试图分配变量Bitmap,因为它是一个正在使用的变量,我会出错。使用(var bitmap…无法分配这是我在执行bitmap=ResizedBitmap(bitmap,10,10)时遇到的错误;位图不能重新分配给同一个变量。请参阅此处:如果需要,您可以将其分配给新的位图变量。Guffa链接中的第一个问题是Form1,而这次是在另一个类中,其中位图是一个使用变量。在Form1中,位图不是一个使用变量。@user1741587:这仍然是完全相同的问题。使用发送到方法中的u未更改。该方法返回一个新位图,即您要使用的已调整大小的图像。