- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
每当我的应用程序尝试通过调用 CreateDIBSection() 或使用 LR_CREATEDIBSECTION
标志调用 LoadImage() 来创建 DIB 部分时,它似乎都会成功返回。它返回的 HBITMAP
是有效的,我可以很好地操作和显示它。
但是,调用 GetLastError() 将返回 8:没有足够的存储空间来处理此命令。
从第一次调用到最后一次调用都会发生这种情况。请求的位图大小似乎无关紧要; 800x600 或 16x16,结果相同。在函数调用之前,GetLastError() 没有返回任何错误;此外,在函数调用之前调用 SetLastError(0) 具有相同的结果。
我发现其他人也问过类似的问题,但事实证明他们正在使用 CreateCompatibleBitmap() 并且当他们切换到 CreateDIBSection() 时问题就消失了,或者他们已经在使用 CreateDIBSection() 并且返回的结果是无效,因此根本不起作用。
既然一切正常,我想我可以忽略它(并在调用任一函数后调用 SetLastError(0)),但这样做可能会忽略一些细微的问题。
当然,这是我正在使用的一些基本代码。首先,调用 LoadImage(),它是我用于很多事情的基本位图类的一部分,我对其进行了相当大的简化以显示更相关的方面:
bool Bitmap::Load( const char* szBitmapName, /*...*/ )
{
m_hBitmap = (HBITMAP)LoadImage( GetModuleHandle( NULL ), szBitmapName,
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
//...
}
// ...
Bitmap::~Bitmap()
{
if( m_hBitmap ) DeleteObject( m_hBitmap );
}
bool Bitmap::Draw( HDC hDC, int iDstX, int iDstY, int iDstWidth,
int iDstHeight, int iSrcX, int iSrcY, int iSrcWidth,
int iSrcHeight, bool bUseMask ) const
{
HDC hdcMem = CreateCompatibleDC( hDC );
if( hdcMem == NULL ) return false;
HBITMAP hOld = (HBITMAP)SelectObject( hdcMem, m_hBitmap );
BLENDFUNCTION blendFunc;
blendFunc.BlendOp = AC_SRC_OVER;
blendFunc.BlendFlags = 0;
blendFunc.AlphaFormat = AC_SRC_ALPHA;
blendFunc.SourceConstantAlpha = 255;
AlphaBlend( hDC, iDstX, iDstY, iDstWidth, iDstHeight, hdcMem, iSrcX,
iSrcY, iSrcWidth, iSrcHeight, blendFunc );
SelectObject( hdcMem, hOld );
DeleteDC( hdcMem );
}
对 CreateDIBSection 的调用通常在更新分层窗口时完成:
HDC hDCScreen( GetDC(0) );
POINT tSourcePos = { 0, 0 };
HDC hDCSource( CreateCompatibleDC( hDCScreen ) );
// iWidth and iHeight are used both for the bitmap size and window size
// to keep this example simpler
BITMAPINFO bi32 = {0};
bi32.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi32.bmiHeader.biWidth = iWidth;
bi32.bmiHeader.biHeight = iHeight;
bi32.bmiHeader.biPlanes = 1;
bi32.bmiHeader.biBitCount = 32;
bi32.bmiHeader.biCompression = BI_RGB;
void* pBits = NULL;
HBITMAP hBitmap = CreateDIBSection(NULL, &bi32, DIB_RGB_COLORS,
(void**)&pBits, NULL, NULL);
HBITMAP hOldBitmap = (HBITMAP)SelectObject( hDCSource, hBitmap );
POINT tWindowPos = { 0, 0 };
SIZE tWindowSize = { iWidth, iHeight };
BLENDFUNCTION blendFunction = {0};
blendFunction.BlendOp = AC_SRC_OVER;
blendFunction.SourceConstantAlpha = 255;
blendFunction.AlphaFormat = AC_SRC_ALPHA;
DWORD iFlags( ULW_ALPHA );
// m_tBitmap is an instance of Bitmap class previously mentioned
m_tBitmap.Draw( hDCSource, 0, 0, iWidth, iHeight, 0, 0, iWidth, iHeight );
UpdateLayeredWindow( GetHandle(), hDCScreen, &tWindowPos, &tWindowSize,
hDCSource, &tSourcePos, 0, &blendFunction, iFlags );
SelectObject( hDCSource, hOldBitmap );
DeleteObject( hBitmap );
DeleteDC( hDCSource );
ReleaseDC( 0, hDCScreen );
任何关于我完全偏离基础的事情的任何指示都将不胜感激。
最佳答案
我认为您没有遵循文档中的内容(来自 CreateDIBSection):
If the function succeeds, the return value is a handle to the newly created DIB, and
*ppvBits
points to the bitmap bit values.If the function fails, the return value is
NULL
, and*ppvBits
isNULL
.This function can return the following value. [...]
如果返回值不是NULL
,则函数成功。调用 GetLastError
不一定会返回任何可靠且有意义的成功信息(来自 GetLastError ):
If the function is not documented to set the last-error code, the value returned by this function is simply the most recent last-error code to have been set; some functions set the last-error code to 0 on success and others do not.
关于c++ - CreateDIBSection 留下 'Not enough storage' 错误,但似乎仍然有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2418776/
每次我尝试构建(执行完整的 Clean,然后构建)时,我都会在 Eclipse 的问题部分下弹出此错误消息。项目本身旁边还显示一个错误。 我已经尝试了同一问题的其他解决方案中包含的所有内容: 删除项目
我收到以下错误(注意:我使用的是 Netbeans): java.sql.SQLException: No suitable driver found for jdbc:derby://localho
例如 //somewhere struct IFace; struct Base { Base(IFace* iface): f(iface) { //wi
我试图通过 stringstream 将 double 变成字符串,但它不起作用。 std::string MatlabPlotter::getTimeVector( unsigned int xve
我正在尝试使用 AudioKit 框架中的音序器播放音频文件。 AudioKit.output = sampler AudioKit.start() sampler.enableMID
昨天我问了一个关于插入 Heroku 的问题。它不工作,然后突然开始工作。我什么都没改变。现在在一个新的应用程序上,我遇到了完全相同的问题。我决定包含我的整个 Gemfile,希望我可以继续没有这种令
我知道,这个topic已经是discussed许多times,所以直截了当。 这是ItemsSource的TabControl: Tabs = new ObservableCollection {
我有一个更新对象的函数,问题是当我从更新表单字段返回到详细 View 时,它初始化旧对象而不是更新后的对象。 我想在 CarService 而不是 app.js 中填充汽车列表 这是我的汽车服务:
在 resolution comments错误报告 12266 (“套接字连接错误导致资源泄漏”),Robert Ehteshamzadeh 写道 TClientSocket is deprecate
我最初发布了一个问题 here 我发现 JTextField 仅在 JScrollPane 存在时才调整大小。换句话说,我可以根据需要最小化和最大化它,直到出现滚动条(因为文本太多,无法放入窗口)。之
我读过关于 postion:absolute 的问题并尝试了几乎所有可能的解决方案。包括相对定位 div,将它们包装在相对定位的父级中等等,但它没有帮助。 我正在绘制一个表格,然后我将 div 放入其
我在这里发起了一个话题document.getElementById not working但看起来即使提出的建议都是有效的,我仍然有问题。 我有几个复选框。当我在这里查看页面源代码时,有。 docu
我正在做一些阅读,试图更好地理解按位运算符,然后偶然发现了 a helpful old blog post from 2012 ,其中指出 - 在随机正整数 x 的奇数测试中 - 在作者的计算机上评估
我正在尝试在 Eclipse Neon 中使用 aspectj 创建一个示例 maven 项目。然而,方面并没有编织/工作(参见下面的输出)。我尝试寻找很多原因和解决方案,但没有一个有效(请参阅下面的
无论我如何配置我的 appsettings.json 和 appsettings.Development.json,除非我手动添加 ConfigureLogging,否则我无法在信息消息下方记录任何内
我正在尝试使用 JQuery .get() 方法和 JavaScript for 循环来处理来自外部文件的一些数据。我已经在 stackoverflow 上阅读了有关闭包和回调返回值的内容几个小时,但
我正在使用 PHP 5.6 并且要打印一些东西,我必须编辑 php.ini 并包含 php_printer.dll 文件。但是 PHP 5.6 没有.dll 文件。 我要解决的问题: 我想将凭证打印机
我目前正在调试一个包含内存泄漏的大(非常大!)C# 应用程序。它主要使用 Winforms 作为 GUI,尽管一些控件是在 WPF 中制作的,并由 ElementHost 托管。直到现在,我发现许多内
[已解决] 看来 PHP MYADMIN 变量成功了。我将 wait_timeout 设置为 30 ,并将 Lock_wait_timeout 设置为 50 花了将近 6 个小时才恢复稳定,包括几次重
我读过几个关于该主题的讨论,有人说 qmake < 3.0 不正确支持该指令。我刚刚为 g++-64 重新安装了 Qt 5.9.1,但问题仍然存在。此外,我尝试过各种 mkspecs/xxx/xxx.
我是一名优秀的程序员,十分优秀!