Aurigma Forums
»
Graphics Mill
»
Discussions – Graphics Mill
»
How to generate a background during a pipeline?
Rank: Advanced Member
Groups: Guest
Joined: 5/10/2017(UTC) Posts: 33
Thanks: 10 times Was thanked: 1 time(s) in 1 post(s)
|
Hello, I want to resize and unsharp a large image Code:
var targetSize = new Size(200, 100);
using (var resize = new Resize(targetSize, ResizeInterpolationMode.Lanczos3, ResizeMode.Fit))
using (var unsharp = new UnsharpMask(0.35f, 1f, 0f))
and then imprint on a white background Code:using (var bgGen = new ImageGenerator(targetSize, reader.PixelFormat, backgroundColor))
but the combiner takes only a topimage as argument (the background ist the image in the pipeline). Since both images are results of a pipeline how do I have to construct that pipeline (preferably without using two separate pipelines)?
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
This code should give you an idea how to implement it: Code:var targetSize = new Size(200, 100);
var backgroundColor = RgbColor.Green;
using (var reader = ImageReader.Create("../../../in.png"))
using (var resize = new Resize(targetSize, ResizeInterpolationMode.Lanczos3, ResizeMode.Fit))
using (var unsharp = new UnsharpMask(0.35f, 1f, 0f))
using (var bgGen = new ImageGenerator(targetSize, reader.PixelFormat, backgroundColor))
using (var combiner = new Combiner())
using (var writer = ImageWriter.Create("../../../out.png"))
{
combiner.Mode = CombineMode.Alpha;
combiner.TopImage = (reader + resize + unsharp);
(bgGen + combiner + writer).Run();
}
Please note, you can manually construct a pipeline instead of using the plus operator: Code:combiner.TopImage = (reader + resize + unsharp);
--> Code:var topImage = new Pipeline();
topImage.Add(reader);
topImage.Add(resize);
topImage.Add(unsharp);
combiner.TopImage = topImage;
You can find more information here: https://www.graphicsmill.com/doc...nes.htm#overlayingImages |
Best regards, Fedor Skvortsov
|
1 user thanked Fedor for this useful post.
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 5/10/2017(UTC) Posts: 33
Thanks: 10 times Was thanked: 1 time(s) in 1 post(s)
|
Thank you. I missed the forest for the trees.
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 5/10/2017(UTC) Posts: 33
Thanks: 10 times Was thanked: 1 time(s) in 1 post(s)
|
Extension of the original question. I want to place the topImage in the middle of the generated background. Code:
var targetSize = new Size(200, 100);
var backgroundColor = RgbColor.Green;
using (var reader = ImageReader.Create("../../../in.png"))
using (var resize = new Resize(targetSize, ResizeInterpolationMode.Lanczos3, ResizeMode.Fit))
using (var unsharp = new UnsharpMask(0.35f, 1f, 0f))
using (var bgGen = new ImageGenerator(targetSize, reader.PixelFormat, backgroundColor))
using (var combiner = new Combiner())
using (var writer = ImageWriter.Create("../../../out.png"))
{
combiner.Mode = CombineMode.Alpha;
var topImage = (reader + resize + unsharp);
combiner.TopImage = topImage;
// this doesn't work
combiner.X = (int)Math.Round((double)(targetSize.Width - topImage.Width) / 2);
combiner.Y = (int)Math.Round((double)(targetSize.Height - topImage.Height) / 2);
(bgGen + combiner + writer).Run();
}
Problem is the new Width and Height of the new topImage are not available. Are they? And, if so, where do I find them? So far I'm back to a separate pipeline.
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
You should specify a target image size explicitly instead of using ResizeMode.Fit: Code:var targetSize = new Size(200, 100);
var backgroundColor = RgbColor.Green;
using (var reader = ImageReader.Create("../../../in.png"))
using (var resize = new Resize())
using (var unsharp = new UnsharpMask(0.35f, 1f, 0f))
using (var bgGen = new ImageGenerator(targetSize, reader.PixelFormat, backgroundColor))
using (var combiner = new Combiner())
using (var writer = ImageWriter.Create("../../../out.png"))
{
var actualTargetSize = Resize.CalculateDimensions(new Size(reader.Width, reader.Height),
targetSize, ResizeMode.Fit);
resize.Width = actualTargetSize.Width;
resize.Height = actualTargetSize.Height;
resize.ResizeMode = ResizeMode.Resize;
combiner.Mode = CombineMode.Alpha;
var topImage = (reader + resize + unsharp);
combiner.TopImage = topImage;
combiner.X = (int)Math.Round((double)(targetSize.Width - actualTargetSize.Width) / 2);
combiner.Y = (int)Math.Round((double)(targetSize.Height - actualTargetSize.Height) / 2);
(bgGen + combiner + writer).Run();
}
|
Best regards, Fedor Skvortsov
|
1 user thanked Fedor for this useful post.
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 5/10/2017(UTC) Posts: 33
Thanks: 10 times Was thanked: 1 time(s) in 1 post(s)
|
|
|
|
|
Aurigma Forums
»
Graphics Mill
»
Discussions – Graphics Mill
»
How to generate a background during a pipeline?
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.