Win32 C/C++从内存缓冲区加载图像
我想在 Win32 应用程序上加载图像 (.bmp) 文件,但我不想使用 Windows API 中的标准 LoadBitmap/LoadImage:我希望它从内存中已有的缓冲区加载。我可以轻松地直接从文件加载位图并将其打印在屏幕上,但这个问题让我陷入困境。
我正在寻找的是一个像这样工作的函数:
HBITMAP LoadBitmapFromBuffer(char* buffer, int width, int height);
I want to load an image (.bmp) file on a Win32 application, but I do not want to use the standard LoadBitmap/LoadImage from Windows API: I want it to load from a buffer that is already in memory. I can easily load a bitmap directly from a file and print it on the screen, but this issue is making me stuck.
What I'm looking for is a function that works like this:
HBITMAP LoadBitmapFromBuffer(char* buffer, int width, int height);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试
CreateBitmap()
:Try
CreateBitmap()
:没关系,我找到了解决方案!这是初始化代码:
Nevermind, I found my solution! Here's the initializing code:
CreateDIBSection 使用起来可能有点复杂,但它可以做的事情之一是创建一个与设备无关的位图,并为您提供一个指向位图位缓冲区的指针。当然,您已经拥有一个充满位图位的缓冲区,但至少您可以复制数据。
推测一下:CreateDIBSection 也可以从文件对象创建位图,并且可能有一种方法可以让 Windows 为您提供代表一块内存的文件对象,这可能会欺骗 CreateDIBSection > 为您提供直接从缓冲区构建的位图。
CreateDIBSection
can be a little complicated to use, but one of the things it can do is create a device-independent bitmap and give you a pointer to the buffer for the bitmap bits. Granted, you already have a buffer full of bitmap bits, but at least you could copy the data.Speculating a bit:
CreateDIBSection
can also create bitmaps from file objects, and there's probably a way to get Windows to give you a file object representing a chunk of memory, which might trickCreateDIBSection
into giving you a bitmap built directly from your buffer.与内存中当前位图大小相同的新位图,并将内存结构写入其上。
不,但您可以创建一个 microsoft.com/en-us/library/dd183485(v=VS.85).aspx" rel="nofollow noreferrer">CreateBitmap 函数。将 lpvBits 设置为您的数据。No, but you can create a new bitmap the size of the current one in memory, and write your memory structure onto it.You're looking for the CreateBitmap function. Set lpvBits to your data.