如何使用GDI将方位图呈现给任意的四边形多边形? [英] How can I render a square bitmap to an arbitrary four-sided polygon using GDI?

查看:205
本文介绍了如何使用GDI将方位图呈现给任意的四边形多边形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要绘制一个方形图像,映射或转换为编译时未知的四边形多边形。如何做到这一点?



更长的解释



具体问题是,矩形地图投影。假设我有以下图块:





我知道四点需要在这里:





鉴于此,我想得到以下输出: p>



方块可能是:




  • 旋转;和/或

  • 在一端比另一端更窄。



认为第二个项目意味着这需要非仿射变换。


随机附加笔记



四面?可能的是,完全正确的是,瓦片应该是
映射到多边形四点,但是为了我们的目的,
,并且按照它被绘制的规模,一个正方形 - >其他四角多边形
转换就足够了。



为什么最好是GDI?到目前为止,所有渲染都是使用GDI完成的,我想保持代码(a)的快速,(b)尽可能少的额外
库。我知道一些支持$ b $在GDI中的b转换,并且今天一直在尝试他们
,但即使在尝试了他们之后,我也不确定他们是否有足够的灵活性来达到这个目的。如果他们是,我没有设法
计算出来,所以我真的很感激一些示例代码。



GDI +也可以,因为我们在其他地方使用它,但我知道这可能很慢,速度是
在这里很重要。



另一个替代方案是任何 Delphi - /
C ++ Builder - 具体;这个程序主要用C ++编写,使用
的VCL,而且所讨论的图形当前被绘制到一个
TCanvas,混合使用 TCanvas方法和原始的WinAPI / GDI调用。



覆盖图像:最后一个注意事项是,瓷砖中的一种颜色可能是颜色键
透明度:也就是说,上述瓷砖
中的所有白色(例如)正方形在绘制时应该是透明的下面是什么
目前,使用目标%29.aspxrel =nofollow noreferrer> 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆