Raspberry Pi和framebuffer输入单声道

时间:2015-02-25 07:13:03

标签: c# mono raspberry-pi framebuffer

我尝试使用mono在内存中渲染位图。此图像应显示在Adafruits 2.8"触摸TFT(320 * 240)。该程序是使用Visual Studio 2013 Community Edition开发的。我想主持一个ASP.NET Web Api和Show 显示屏上的一些数据。 ASP.NET部分工作正常,图像呈现。我的想法是将Image写入帧缓冲区输入,但是这样做我得到一个Exception,说文件很大。我只是在没有BMP标题的情况下编写原始数据。有人管理过吗?也许创造形象是 错误。 似乎发生了一些事情,因为显示器发生了变化,我可以看到可能来自我的图像的白色区域。 我不想使用任何额外的库来保持简单。所以我的想法是直接使用FBI。有谁知道这个问题和解决方案?

以下是我的一些代码:

using (Bitmap bmp = new Bitmap(240, 320, PixelFormat.Format16bppRgb555))
{
    [...]
    Byte[] image = null;

    using(MemoryStream memoryStream = new MemoryStream())
    {
        bitmap.Save(memoryStream, ImageFormat.Bmp);

        Byte[] imageTemp = memoryStream.GetBuffer();
        //Remove BMP header
        image = new Byte[imageTemp.Length - 54];
        Buffer.BlockCopy(imageTemp, 54, image, 0, image.Length);
        //153600 byte
        using (FileStream fb1 = new FileStream("/dev/fb1", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
        {
            fb1.Write(image, 0, image.Length);
            fb1.Close();
        }
    }
}

2 个答案:

答案 0 :(得分:0)

看一下http://computerstruggles.blogspot.de/2013/02/how-to-program-directfb-in-c-on.html - 想法是安装directfb库并使用C#和PInvoke来使用它。该博客的作者在C中使用了一个迷你包装器,使其更容易使用。 BTW为什么你不想安装额外的图书馆并从其他人为你做的工作中获利?

答案 1 :(得分:0)

当MemoryStream重新分配内存时,可能内存不足。当它需要生长时,它的大小翻倍。通过这么大的写入,内部缓冲区可能超过可用内存。有关详细信息,请参阅Why does C# memory stream reserve so much memory?