Grid composition from multiple images. #1301
Replies: 1 comment
-
Looks like I've rushed the question and was able to find a solution with a bit more experimentation. I'll post the solution in case someone comes across the thread and needs a quick code example to work with. If I understand correctly the To get a grid of the inputs I used the public void SaveGrid(string[] data, string path)
{
using (var images = new MagickImageCollection())
{
// Iterate over the images that are passed in as Base64 strings
foreach (var image in data)
{
// Convert to byte[] and create a new MagickImage to add to the images collection
images.Add(new MagickImage(Convert.FromBase64String(image)));
}
// Get the image size from the first image, if they differ in resolution a new approach needs to be implemented
var width = images[0].Width;
var height = images[0].Height;
// Call the Montage method with the required Geometry size and an optional parameter for Background Color
using (var result = images.Montage(new MontageSettings() { Geometry = new MagickGeometry(width, height), BackgroundColor = MagickColors.Black }))
{
result.Write(path);
}
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This might be quite an obvious question but I'm still learning the framework and ImageMagick in general, sorry for my inexperience.
My goal is to create a squared grid of a varying amount of images. I tried this example but providing 2 images with the same aspect ratio and resolution, the output is just the second image. The images are loaded as byte arrays converted from base64, inspecting the objects with the debugger they seem to be fine. Not sure if I'm missing some kind of setting to make it work has I expect.
Reading the IM documentation I also found the Montage command and the Concatenate mode that looks like what I'm trying to achieve but I wasn't able to find a way to use that mode with the Magick.NET implementation of Montage, is that a missing feature?
Beta Was this translation helpful? Give feedback.
All reactions