-
|
I need to add solid-colored rounded corners to an image. Specifically, I want to use a rounded rectangle to divide the rectangular image into inner and outer regions, overlaying a solid color on the outer region. The solid color includes an alpha channel, so when alpha is not at maximum, it provides partial transparency, allowing some of the original image to show through. using ImageMagick;
using ImageMagick.Drawing;
using static ImageMagick.CompositeOperator;
using static ImageMagick.MagickColors;
using MagickImage img = new("lena_std.tif");
var (w, h) = (img.Width, img.Height);
var r = .3 * Math.Min(w, h);
using MagickImage mask = new(Black, w, h);
new Drawables().FillColor(White).RoundRectangle(0, 0, w, h, r, r).Draw(mask);
img.SetWriteMask(mask);
using MagickImage colorLayer = new(Aqua, w, h);
img.Composite(colorLayer, Over);
img.RemoveWriteMask();
img.Write("lena_std_mod1.tif");It works. But to reduce memory usage, I want to use Drawables instead of colorLayer. ...
img.SetWriteMask(mask);
new Drawables().FillColor(Aqua).Rectangle(0, 0, w, h).Draw(img);
img.RemoveWriteMask();
img.Write("lena_std_mod2.tif");The result is a transparent center and solid-colored corners, without anything of Lena. Is Drawables.Draw() supposed to ignore WriteMask? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Already answered here: #1963? |
Beta Was this translation helpful? Give feedback.
Already answered here: #1963?