如何使用 GDI 将方形位图渲染为任意四边多边形? [英] How can I render a square bitmap to an arbitrary four-sided polygon using GDI?
问题描述
我需要绘制一个正方形图像,映射或转换为编译时未知的四边多边形.我该怎么做?
详细解释
具体问题是使用非矩形地图投影渲染地图图块.假设我有以下磁贴:
而且我知道四个角点必须在这里:
鉴于此,我想得到以下输出:
方形图块可能是:
- 旋转;和/或
- 一端比另一端窄.
我认为第二项意味着这需要一个非仿射变换.
<块引用>随机附加注释
四边形? 完全正确的说法是,瓷砖应该是映射到具有四个以上点的多边形,但出于我们的目的并按照绘制的比例,一个正方形 -> 其他四角多边形转换应该就够了.
为什么最好只使用 GDI? 到目前为止所有的渲染都是使用 GDI 完成的,我希望保持代码 (a) 快速和 (b) 需要很少的额外图书馆尽可能.我知道 一些支持GDI 中的转换 并一直在试验它们今天,但即使在对它们进行试验之后,我也不确定它们是否为此目的足够灵活.如果他们是,我还没有设法弄清楚,所以我真的很感激一些示例代码.
GDI+ 也可以,因为我们在别处使用它,但我知道它可能很慢,而且速度是这里很重要.
另一种选择是Delphi-/C++Builder 特定;这个程序主要是用 C++ 编写的VCL 和有问题的图形当前被绘制成TCanvas 混合了 TCanvas 方法和原始 WinAPI/GDI 调用.
叠加图像:最后一个警告是磁贴中的一种颜色可能用于颜色键透明度:即上面图块中的所有白色(比如说)方块当绘制在下面的任何东西上时应该是透明的.目前,瓷砖被绘制为正方形或轴对齐的矩形使用 TransparentBlt 的目标.>
我很抱歉所有额外的警告使这个问题变得更加复杂而不是我应该使用什么算法?"但我会很乐意接受答案也只有算法信息.
您可能还想看看 Graphics32.下面的屏幕截图显示了 GR32 中的转换演示如何看起来像
I need to paint a square image, mapped or transformed to an unknown-at-compile-time four-sided polygon. How can I do this?
Longer explanation
The specific problem is rendering a map tile with a non-rectangular map projection. Suppose I have the following tile:
and I know the four corner points need to be here:
Given that, I would like to get the following output:
The square tile may be:
- Rotated; and/or
- Be narrower at one end than at the other.
I think the second item means this requires a non-affine transformation.
Random extra notes
Four-sided? It is plausible that to be completely correct, the tile should be mapped to a polygon with more than four points, but for our purposes and at the scale it is drawn, a square -> other four-cornered-polygon transformation should be enough.
Why preferably GDI only? All rendering so far is done using GDI, and I want to keep the code (a) fast and (b) requiring as few extra libraries as possible. I am aware of some support for transformations in GDI and have been experimenting with them today, but even after experimenting with them I'm not sure if they're flexible enough for this purpose. If they are, I haven't managed to figure it out, and so I'd really appreciate some sample code.
GDI+ is also ok since we use it elsewhere, but I know it can be slow, and speed is important here.
One other alternative is anything Delphi- / C++Builder-specific; this program is written mostly in C++ using the VCL, and the graphics in question are currently painted to a TCanvas with a mix of TCanvas methods and raw WinAPI/GDI calls.
Overlaying images: One final caveat is that one colour in the tile may be for color-key transparency: that is, all the white (say) squares in the above tile should be transparent when drawn over whatever is underneath. Currently, tiles are drawn to square or axis-aligned rectangular targets using TransparentBlt.
I'm sorry for all the extra caveats that make this question more complicated than 'what algorithm should I use?' But I will happily accept answers with only algorithmic information too.
You might also want to have a look at Graphics32. The screen shot bewlow shows how the transfrom demo in GR32 looks like
这篇关于如何使用 GDI 将方形位图渲染为任意四边多边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!