- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有将 opencv 图像转换为位图的代码:
void processimage(MAT imageData)
{
Gdiplus::Bitmap bitmap(imageData.cols,imageData.rows,stride, PixelFormat24bppRGB,imageData.data);
// do some work with bitmap
}
当图像尺寸为 2748 X 3664 时它工作正常。但是我试图处理尺寸为 1374 X 1832 的图像,它不起作用。
错误是无效参数(2)。
我检查过并可以确认:
在 2748 *3664 中:
1374 X 1832
所以对我来说一切似乎都是正确的,但它会产生错误。
问题是什么,我该如何解决?
基于解释为什么我不能创建位图的答案。我最终是这样实现的:
Mat newImage;
cvtColor(imageData, newImage, CV_BGR2BGRA);
Gdiplus::Bitmap bitmap(newImage.cols,newImage.rows,newImage.step1(), PixelFormat32bppRGB,newImage.data);
如此有效,我将输入图像转换为每像素 4 字节,然后使用将其转换为位图。
感谢 Roger Rowland 的回答。
最佳答案
我认为问题在于 BMP 格式的步幅必须是 4 的倍数。
您的大图的步幅为 8244,这是有效的 (8244/4 = 2061),但您的小图的步幅为 4122,这不是 (4122/4 = 1030.5)。
作为it says on MSDN对于 stride 参数(我强调):
Integer that specifies the byte offset between the beginning of one scan line and the next. This is usually (but not necessarily) the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) multiplied by the width of the bitmap. The value passed to this parameter must be a multiple of four.
假设您的步幅是正确的,我认为您唯一的选择是逐行复制它。所以,像这样:
Gdiplus::Bitmap
所需的大小和格式关于c++ - 将 opencv 图像转换为 gdi 位图不起作用取决于图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20743134/
这两个库之间有什么区别吗? 最佳答案 根据the wikipedia article on GDI : With the introduction of Windows XP, GDI was dep
我喜欢 GDI+,因为它具有高性能并且包含在 Windows XP 中。但是,它的模糊类和效果类仅在 GDI+ 1.1 中可用,后者仅随 Windows Vista 或更高版本提供。尽管微软计划很快放
我用 C# 创建了一个图像服务,它采用基础层图像 (JPG),再分层一层更透明的 PNG(32 位),然后输出最终的 JPG 图像。我试图从这个函数中挤出最后一毫秒,但我的代码在 GDI+ 中的 Dr
我正在使用顶点以及 LineTo() 和 MoveTo() 函数制作一系列三角形来表示 3D 形状。 着色/填充这些三角形的最佳方法是什么? 谢谢 最佳答案 MSDN has a sample tha
我在 Win7 系统上注意到过一个问题,以为是 DWM 错误,但在重新启动后已修复。但现在我意识到它在其他人的系统上发生(作为默认行为),并且这也是 Surface Pro 上的正常行为。 如何重现问
是否可以在用户模式下创建自定义 GDI 设备?我们的想法是创建一个设备上下文 (HDC),我们可以将其传递给不透明的组件,这样当组件调用 GDI 函数(如 TextOut)时,我们可以获得实际的文本字
我想知道是否可以枚举所有桌面可见窗口以创建它们的位图并将所有位图组合成一个以便获得桌面的完整屏幕截图? 最有可能使用 GDI/GD+,但也欢迎使用任何外部库。首选语言C\C++。 提前致谢。 最佳答案
我有一个生成元文件 (EMF) 的应用程序。它使用引用设备(又名屏幕)来呈现这些元文件,因此元文件的 DPI 会根据代码运行的机器而变化。 假设我的代码打算创建一个 8.5 x 11 英寸的元文件。
我在同时使用 GDI 和 GDI+ 进行绘图时遇到问题。页面转换——尤其是缩放——似乎在两者之间有点偏离。除了 SetViewportExt 和 SetWindowExt 之外,GDI 上下文的哪些属
我需要从应用程序中获取一个大表(300K+ 行)并且没有导出功能。经过多次不成功的尝试后,我只剩下一个复制粘贴宏,一次一行。如果有办法在绘制时获取字符串,我可以一次获取一页(40 行)。 最佳答案 如
我曾经在我的 Win7 系统上注意到一个问题,认为这是一个 DWM 错误,因为它在重新启动后得到修复。但现在我意识到它正在其他人的系统上发生(作为默认行为),这也是 Surface Pro 上的正常行
我正在寻找一些高级教程,或者可能是用 C++ 或 .NET 编写的开源应用程序,它们可以实现复杂的基于 vector 的应用程序,例如 MS Visio 或 Autocad。我需要知道的是,当用户可以
我正在使用第三方库来绘制图表。该库需要一个 HDC (GDI)。但是我的应用程序使用的是 GDI+。 Q1:这样做安全吗? void f(Gdiplus::Graphics& graphics) {
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 4年前关闭。 Improve t
对不起,如果这是题外话。如果是这样的话;请随时将其移至适当的站点。 GDI/GDI+ 如何在不使用 DirectX 或 OpenGL 等较低级别的 API 与 GPU 通信的情况下渲染到显卡(在屏幕上
我正在尝试在兼容的渲染目标上使用 Gdi 和 Direct 2D 来渲染位图。我使用 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_GDI_COMPATIBLE 选项创建
我们目前正在将一个较旧的应用程序转换为通过 GDI+ 绘制,而不是直接使用 GDI。随着我们逐步翻译系统,有时我们需要从 Gdiplus::Graphics 对象中获取 HDC,以便允许尚未翻译的代码
我正在尝试使用 GDI+ 在屏幕上(整个屏幕,在所有其他窗口的顶部)绘图。 我已将 NULL 传递给 GetDC 以将 HDC 显示到屏幕上,然后使用它创建一个 Graphics 对象,并使用 Dra
GDI+ 非常慢,几乎完全是软件,而 GDI 是高度硬件加速的。GDI+ 是 Graphics 类在 WinForms 上使用的东西,它太慢了。 有没有人制作了 .NET GDI 库以便我们可以有速度
ASP.NET 网站随机引发此 System.Drawing-error: System.Runtime.InteropServices.ExternalException:System.Drawin
我是一名优秀的程序员,十分优秀!