Question

I have a function that converts raw byte data to bitmap, to be displayed. The process is being done in an embedded platform with Windows CE 6.0. This function works. However, the conversion time is too long.

I am not sure whether the issue stems from either my logic or other reasons. Please advice.

    private  Bitmap GetBitMap(byte[] byImage)
    {
        Bitmap bm = new Bitmap(IMG_X, IMG_Y);
        for (int j = 0; j < IMG_Y; j++)
        {
            for (int i = 0; i < IMG_X; i++)
            {
                int rgb = (int)byImage[i + j * IMG_X];
                Color color = Color.FromArgb(rgb, rgb, rgb);
                bm.SetPixel(i, j, color);
            }
        }
        return bm;
    }
Était-ce utile?

La solution

It seems that you are using .NET and this may not the most efficent solution if you need to perform image processing. The .NET Compact Framework is pretty efficent and productive if you plan to develop high-level apps, UIs etc. but being just in time compiled the machine code generated can't be as optimized as code generated from a native compiler. You are also using high-level bitmap class to perform your conversion and each setPixel call will use many CPU cycles. You may write some C/C++ code to perform this operation, write bitmap data directly in memory and definitely reduce the CPU time required for the conversion

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top