1

这是代码:

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 帧应该很快,不是吗?

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

谢谢。

4

3 回答 3

3

它应该是

bitmap = ResizeBitmap(bitmap, 10, 10);

您没有将调整大小的位图分配给任何东西。

于 2012-10-30T23:31:51.453 回答
0

方法返回位图,所以需要使用方法的返回值:

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

仍然与此处相同的答案:如何在此函数中调整位图的大小?

于 2012-10-30T23:32:36.180 回答
0

在您的第一个代码示例的底部附近使用它:

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 --;
}

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

于 2012-10-30T23:40:01.267 回答