Graphics32提供了一个Image Wrapping示例(\ Transformation \ ImgWarping_Ex),用户可以使用画笔来包装bitmap32的一部分。然而,这个例子很难理解,因为它混合了许多复杂的概念。如何使用Graphics32环绕转换来转换多边形区域?
比方说,我需要一个包裹转换,它将多边形区域从一个形状转换到另一个形状。我怎么能够完成这样的任务?
Graphics32提供了一个Image Wrapping示例(\ Transformation \ ImgWarping_Ex),用户可以使用画笔来包装bitmap32的一部分。然而,这个例子很难理解,因为它混合了许多复杂的概念。如何使用Graphics32环绕转换来转换多边形区域?
比方说,我需要一个包裹转换,它将多边形区域从一个形状转换到另一个形状。我怎么能够完成这样的任务?
正如在评论中,我不确定多边形的多边形。但是,要将一个四边形转换为另一个,可以使用投影变换。这将由四个点组成的四边形映射到四个点的另一个四边形。 (我最初发现了这个时候I asked this SO question。)
您:
光栅化器至少是可选的,但通过指定高质量(较慢)的光栅化器链而不是默认值,您将获得更高质量的输出。还有其他可选参数。
它们的关键是TProjectiveTransformation
对象。不幸的是,Graphics32文档似乎缺少Transform method
的条目,所以我无法链接到该条目。不过,这里有一些未经测试的示例代码,基于我的一些代码。它把一个长方形的源图像向凸四边形的目标图像:
var
poProjTransformation : TProjectiveTransformation;
poRasterizer : TRegularRasterizer;
oTargetRect: TRect;
begin
// Snip some stuff, e.g. that
// poSourceBMP and poTargetBMP are TBitmap32-s.
poProjTransformation := TProjectiveTransformation.Create();
poRasterizer := TRegularRasterizer.Create();
// Set up the projective transformation with:
// the source rectangle
poProjTransformation.SrcRect = FloatRect(TRect(...));
// and the destination quad
// Point 0 is the top-left point of the destination
poProjTransformation.X0 = oTopLeftPoint.X();
poProjTransformation.Y0 = oTopLeftPoint.Y();
// Continue this for the other three points that make up the quad
// 1 is top-right
// 2 is bottom-right
// 3 is bottom-left
// Or rather, the points that correspond to the (e.g.) top-left input point; in the
// output the point might not have the same relative position!
// Note that for a TProjectiveTransformation at least, the output quad must be convex
// And transform!
oTargetRect := TTRect(0, 0, poTarget.Width, poTarget.Height)
Transform(poTargetBMP, poSourceBMP, poProjTransformation, poRasterizer, oTargetRect);
// Don't forget to free the transformation and rasterizer (keep them around though if
// you're going to be doing this lots of times, e.g. on many images at once)
poProjTransformation.Free;
poRasterizer.Free;
光栅化是图像质量的重要参数 - 上面的代码将会给你一些工作,但不漂亮,因为它会使用最近邻居抽样。您可以构建一系列对象以获得更好的结果,例如将TSuperSampler
与TRegularRasterizer
一起使用。您可以read about samplers and rasterizers and how to combine them here.
也有对Transform
方法大约五个不同的过载,它的价值脱脂阅读他们在GR32_Transforms.pas
文件的界面让你知道你可以使用什么版本。
谢谢你的回答,但我很抱歉我不需要投影转换,我需要在Graphics32演示中显示的包装转换:Transformation \ ImgWarping_Ex – jonjbar 2012-08-08 11:11:40
我真的不知道从哪里开始,这就是我需要的:一个简单的起点。 – jonjbar 2012-08-04 05:10:26
你需要一个多边形多边形,还是四边形?我可以帮忙,但我没有使用任何更高阶的形状。 – 2012-08-06 12:14:34
四边形多边形将是一个很好的起点。我感谢您可以提供任何帮助,提前致谢! – jonjbar 2012-08-06 17:54:17