使用非矩形形状在 Flex 中裁剪图像

发布于 2024-08-09 08:10:07 字数 307 浏览 9 评论 0原文

我一直在按照本教程在 Flex 中裁剪图像: http://code.mediablur.com /ImageCropper/ImageCropperDemo.html

其裁剪的核心是使用一种称为“copyPixels”的方法。然而,该方法将矩形形状作为其裁剪区域的参数之一。我可以使用其他策略来裁剪它而不是使用矩形吗?

我将让用户指定应该使用一系列点裁剪的区域。

I've been following this tutorial to crop images in flex: http://code.mediablur.com/ImageCropper/ImageCropperDemo.html.

At the heart of its cropping is using a method called "copyPixels". However, this method takes as one of its arguments a rectangular shape for its crop region. Are there other strategies I can use to crop it not using a rectangle.

I am going after letting the user specify the region that should be cropped using a series of points.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晚风撩人 2024-08-16 08:10:07

当然,生成的图像必须是矩形,但您可以使用 BitmapData.drawBlendMode

var originalImage:BitmapData; // defined
var maskPath:GraphicsPath; // defined

var maskShape:Shape = new Shape();
maskShape.graphics.beginFill(0, 0); // fill region with transparent
maskShape.graphics.drawRect(0, 0, originalImage.width, originalImage.height);
maskShape.graphics.endFill();

maskShape.graphics.beginFill(0xFF0000);
maskShape.graphics.drawPath(maskPath.commands, maskPath.data, maskPath.winding);
maskShape.graphics.endFill();

var resultImage:BitmapData = originalImage.clone();
resultImage.draw(maskShape, null, null, BlendMode.ALPHA);

对于裁剪,您可能会在最后几行中做一些更奇特的事情 - 复制一个区域而不是克隆整个区域originalImage,和/或在应用 maskShape 时应用变换。

(我认为有必要使用 DisplayObject 来使用 BlendMode,但这在文档中并不清楚。)

The resulting image has to be a rectangle, of course, but you can mask with transparency using BitmapData.draw and BlendMode:

var originalImage:BitmapData; // defined
var maskPath:GraphicsPath; // defined

var maskShape:Shape = new Shape();
maskShape.graphics.beginFill(0, 0); // fill region with transparent
maskShape.graphics.drawRect(0, 0, originalImage.width, originalImage.height);
maskShape.graphics.endFill();

maskShape.graphics.beginFill(0xFF0000);
maskShape.graphics.drawPath(maskPath.commands, maskPath.data, maskPath.winding);
maskShape.graphics.endFill();

var resultImage:BitmapData = originalImage.clone();
resultImage.draw(maskShape, null, null, BlendMode.ALPHA);

For cropping, you would probably do something more fancy in the last few lines--copying a region instead of cloning the whole originalImage, and/or applying a transform when applying the maskShape.

(I believe it's necessary to use a DisplayObject to use BlendModes, but that's not clear in the documentation.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文