- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我目前正在编辑一些旧的 GDI 代码以使用 GDI+,但在绘制具有透明背景的 BMP 文件时遇到了问题。旧的 GDI 代码没有使用任何明显的额外代码来绘制透明背景,所以我想知道如何使用 GDI+ 实现这一点。
我现在的代码是这样的
HINSTANCE hinstance = GetModuleHandle(NULL);
bmp = Gdiplus::Bitmap::FromResource(hinstance, MAKEINTRESOURCEW(IDB_BMP));
Gdiplus::Graphics graphics(pDC->m_hDC);
graphics.DrawImage(&bmp, posX, posY);
我还尝试通过使用克隆方法从资源中创建一个新的位图,并将位图绘制到新创建的位图上,但都没有帮助。两次我都使用 PixelFormat32bppPARGB。
然后我尝试使用 alpha 混合,但这样整个图像变得透明,而不仅仅是背景:
Gdiplus::ColorMatrix clrMatrix = {
1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.5f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f
};
Gdiplus::ImageAttributes imgAttr;
imgAttr.SetColorMatrix(&clrMatrix);
graphics.DrawImage(&bmp, destRect, 0, 0, width(), height(), Gdiplus::UnitPixel, &imgAttr);
透明度信息已经包含在图像中,但我不知道如何在绘制图像时应用它。如何实现这一目标?
最佳答案
迟到的答案但是:
ImageAttributes imAtt;
imAtt.SetColorKey(Color(255,255,255), Color(255,255,255), ColorAdjustTypeBitmap);
将使 白色 (255,255,255)
在您使用此图像属性的任何位图上透明。
关于c++ - GDI+绘制透明BMP的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11684455/
这两个库之间有什么区别吗? 最佳答案 根据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
我是一名优秀的程序员,十分优秀!