Graphics32提供了图像包装示例(\Transformation\ImgWarping_Ex),用户可以在其中使用画笔包装bitmap32的一部分。然而,这个示例确实很难理解,因为它混合了许多复杂的概念。
假设我需要一个包装变换,它将一个多边形区域从一个形状转换到另一个形状。我怎样才能完成这项工作呢?
发布于 2012-08-07 13:51:57
和在评论中一样,我不确定一个多边多边形。但是,要将一个四边形转换为另一个四边形,可以使用投影变换。这是由四点组成的四边形到四点四边形的映射。(我最初是在我问了这么多问题时发现的。)
你:
栅格至少是可选的,但是您可以通过指定一个高质量(慢一点)的光栅器链来获得高质量的输出,而不是默认的。还有其他可选参数。
它们的键是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一起使用。你可以阅读有关采样器和栅格器以及如何将它们组合在这里。
对于Transform方法,还有五种不同的重载,值得在GR32_Transforms.pas文件的接口中浏览它们,这样您就可以知道可以使用哪些版本。
https://stackoverflow.com/questions/11781603
复制相似问题