本文介绍了如何转换为位图字节[,,]快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的功能:

    public static byte[, ,] Bitmap2Byte(Bitmap image)
    {
        int h = image.Height;
        int w = image.Width;

        byte[, ,] result= new byte[w, h, 3];

        for (int i = 0; i < w; i++)
        {
            for (int j = 0; j < h; j++)
            {
                Color c= image.GetPixel(i, j);
                result[i, j, 0] = c.R;
                result[i, j, 1] = c.G;
                result[i, j, 2] = c.B;
            }
        }

        return result;
    }

但它需要近6秒转换1800x1800的图像。我可以做得更快?

But it takes almost 6 seconds to convert 1800x1800 image. Can I do this faster?

没关系。想通了。

修改3:
做好了。 0,13s VS 5,35s:)

EDIT 3:Made it. 0,13s vs 5,35s :)

推荐答案

您可以大大通过使用从的BitmapData 对象加快这> Bitmap.LockBits 。谷歌C#位图LockBits为一堆例子。

You can speed this up considerably by using a BitmapData object which is returned from Bitmap.LockBits. Google "C# Bitmap LockBits" for a bunch of examples.

GetPixel 是痛苦的,痛苦的缓慢,使得它(讽刺)完全不适合单个像素的操作。

GetPixel is painfully, painfully slow, making it (ironically) completely unsuitable for the manipulation of individual pixels.

这篇关于如何转换为位图字节[,,]快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 22:16