16 bpp 到 32 bpp 转换
我们有一个需要 32 bpp 数据的编码器库。我们有一个屏幕捕获库,也需要支持 16 bpp。每当我需要将新的屏幕截图传递给编码器时,我想将 16bpp 原始数据转换为 32bpp。如何才能有效地完成这项工作?还有其他替代方案吗?
我不想更改编码器库,因为这也需要更改编码器的上游。
谢谢!
We have a encoder library which takes 32 bpp data. We have a screen capture library which needs to support 16 bpp as well. I would like to convert a 16bpp raw data into 32bpp whenever I need to pass the new screen captures to encoder. How can it be done efficiently and are there any other alternatives ?
I dont want to change the encoder library because that will require changes upstream of encoder as well.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将源位图加载到 HBITMAP 中,创建具有所需像素格式的目标位图,然后将源绘制到目标上。这将是最简单的方法。
如果您想直接使用这些位,那么这是可能的,但让系统为您担心会更容易。当系统执行此操作时,它可能会更快,因为它会得到很好的优化。
You could load the source bitmap into an HBITMAP, create a destination bitmap with the desired pixel format and then draw the source onto the destination. That would be the easiest way to do it.
If you wanted to work directly with the bits then that would be possible but it's easier to let the system worry about it for you. It's probably quicker when the system does it because it will be well optimised.
要澄清其他答案:您需要使用 CreateDIBSection 以您感兴趣的格式创建位图:16bpp 和 32bpp。
此函数的方便之处在于它返回一个指向带有像素数据的内存缓冲区的指针,使您可以轻松地从一个源初始化位图,并提取像素数据以提供给编码器库。
源位图不需要是 DIBSection,它可以是任何类型的 HBITMAP(只要它与您尝试将其选择到的 HDC 兼容 - 但屏幕捕获库将为您提供与屏幕 DC 兼容的HBITMAP(如果它为您提供了 HBITMAP),
然后可以使用 BitBlt 让设备驱动程序执行格式转换。
To clarify the other answers: you need to use CreateDIBSection to create bitmaps in the formats you are interested in: 16bpp and 32bpp.
The handy thing with this function is it returns a pointer to the memory buffer with the pixel data, allowing you to easily initialize the bitmap from the one source, and extract the pixel data to give to the encoder library.
The source bitmap doesn't need to be a DIBSection, it can be any kind of HBITMAP at all (as long as its compatible with the HDC you try to select it into - but the screen capture library will be giving you a screen DC compatible HBITMAP if it gives you an HBITMAP at all)
BitBlt can then be used to get the device driver to perform the format conversion.
使用 BitBlt:
“如果源设备上下文和目标设备上下文的颜色格式不匹配,则 BitBlt 函数将转换源颜色格式以匹配目标格式。”
http://msdn.microsoft.com/en -us/library/dd183370%28v=VS.85%29.aspx
Use BitBlt:
"If the color formats of the source and destination device contexts do not match, the BitBlt function converts the source color format to match the destination format."
http://msdn.microsoft.com/en-us/library/dd183370%28v=VS.85%29.aspx