将32位帧转换为24位帧 [英] Convert 32bit frame to 24bit fram

查看:163
本文介绍了将32位帧转换为24位帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我想将32位帧转换为24位以将其传递给AForge过滤器。我使用图形进行如下操作:



位图bmap =新位图(640,480,System.Drawing.Imaging.PixelFormat.Format32bppRgb);

clone = new Bitmap(bmap.Width,bmap.Height,System.Drawing.Imaging.PixelFormat.Format24bppRgb);





using(Graphics gr = Graphics.FromImage(clone))

{

gr.DrawImage(bmap,new System.Drawing.Rectangle(0,0,clone。宽度,

clone.Height));

}



但需要大量内存,还有其他办法吗?



提前谢谢

Hi. I want to convert a 32 bit frame to 24 bit to pass it to AForge filters. I am doing it using graphics as follow:

bitmap bmap = new Bitmap(640, 480 , System.Drawing.Imaging.PixelFormat.Format32bppRgb);
clone = new Bitmap(bmap.Width, bmap.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);


using (Graphics gr = Graphics.FromImage(clone))
{
gr.DrawImage(bmap, new System.Drawing.Rectangle(0, 0, clone.Width,
clone.Height));
}

but it takes large amounts of memory, is there any other way to do it?

Thanks in advance

推荐答案

看起来你有一个性能泄漏。以下是发生的情况:您使用AForge.NET完成某项任务,但它需要不同的位格式,因此您还可以转换为24位像素格式。我认为你的步骤非常合理,但你的性能仍然比实时视频所要求的要低一些。这是否意味着您无法提高性能(不使用本机代码)?我不这么认为。



这是发生的事情:你至少做了一些双重工作。在内部, System.Drawing 做了很多事情:它读取数据,解释数据,将比特放到画布上,类似的东西。 AForge.NET后来至少再次完成了部分内容。从逻辑上讲,解决方案是删除冗余。以下是我的想法:



It looks like you have a performance leak. Here is what happens: you to accomplish some task with AForge.NET, but it requires different bit format, so you also convert to the 24-bit pixel format. I think your steps are quite reasonable, but you still get a bit less performance than requited by real-time video. Does it mean that you cannot improve performance (without resorting to native code)? I don't think so.

Here is what happens: you really do at least some of double work. Internally, System.Drawing does a number of things: it reads data, interprets it, put bits to canvas, something like that. And AForge.NET later does at least part of it again. Logically, the resolution would be to remove redundancy. Here are the ideas I have:

  1. 通过查看AForge.NET的源代码排除重新格式化像素。使用您现在使用的方法修改或更新AForge.NET,但使用像素格式。我的工作意义重大,但我确信这很有可能。您只需复制并稍微修改代码。
  2. 您说您只需要移动像素。听起来很简单。最有可能的是,您可以在不使用AForge.NET的情况下解决问题。您需要锁定像素(专用数据固定,用于 System.Drawing 中可用的像素。具体方法如下:

    http://msdn.microsoft.com/ en-us / library / system.drawing.bitmap.lockbits%28v = vs.110%29.aspx [ ^ ]。



    上面引用的两种方法的MSDN文章附带了代码示例,可以帮助您了解如何使用它们。您有两种可能通过删除冗余处理来提高性能:

    a)您可以有两个具有不同像素格式的位图,用于更改目标位图的像素格式,但这次您可以在相同的锁定位会话中进行图像转换,避免来回多余的像素编组,这应该是一次相当大的偷听;

    b)你可以像以前一样使用32位的像素格式;在这种情况下,您可以对同一组位进行所有转换,将图像封送到数据和数据仅映像一次。
  1. Exclude reformatting pixels by looking at the source code of AForge.NET. Modify or update AForge.NET with the methods you use now, but working with your pixel formats. I means considerable job, but I'm sure it's quite possible. You just copy and slightly modify the code.
  2. You say that you just need to shift pixels. It sounds very simple. Most likely, you can work it out without using AForge.NET. You need to lock the pixels (specialized data pinning for pixels available in System.Drawing. Here is how:
    http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits%28v=vs.110%29.aspx[^].

    The MSDN articles on two methods referenced above comes with code samples which can help you to understand how to use them. You have two possibilities to improve performance by removing redundant processing:
    a) you can have two bitmaps with different pixel format, to change pixel format of the target bitmap, but this time you can do your image transformation in the same "lock bit session", avoiding redundant marshaling of pixel back and forth, which should be a considerable overhear;
    b) you can work with the same pixel format, as before, the 32-bit one; in this case, you can do all the transformation on the same set of bits, marshaling the image to data and data to image only once.





请试试。祝你好运!



-SA


这篇关于将32位帧转换为24位帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆