This project has moved and is read-only. For the latest updates, please go here.

Mosaic different size images

Nov 29, 2016 at 3:18 PM
I'm trying to add a small image to a blank canvas, and then overlay a translucent background image (the same size as the canvas) over all this. And then output as a .gif file.

Here' the code I'm using, the file I get in the end is just the smaller sized image.
                    using (var images = new MagickImageCollection())
                    {

                        using (var canvas = new MagickImage(new MagickColor(Color.Gray), 300, 300))
                        {
                            smallImage.Resize(90, 90);
                            var smallImageDraw = new Drawables();

                            smallImageDraw.Draw(smallImage);
                            smallImageDraw.Point(100,100);
                            smallImageDraw.Rotation(-50);
                            canvas.Draw(smallImageDraw);

                            images.Add(smallImage);

                            var bgImage = new MagickImage(FileSystem.GetFullPath(frameData.Item.FilePath));

                            var bgDraw = new Drawables();

                            bgDraw.Draw(bgImage);
                            bgDraw.Point(canvas.Width, canvas.Height);
                            canvas.Draw(bgDraw);

                            images.Add(canvas);

                            images.Mosaic();
                        }

                        using (var frameMs = new MemoryStream())
                        {
                            images.Write(frameMs, MagickFormat.Png);
                            frameMs.Position = 0;
                            var fileName = string.Format("layers/{2}-{0}-{1:dd-MM-yyyy-hh-mm-ss}.png", Guid.NewGuid(), DateTime.Now, frameData.Index);
                            FileSystem.AddFile(fileName, frameMs);
                            gifFrames.Add(fileName, frameData.Item.Delay);
                        }                      
                    }                
Is sometihng being done in the wrong order? Or is Drawable the wrong thing to be using?
Nov 29, 2016 at 7:33 PM
I am not sure what you are trying to accomplish but I don't think you will need the Drawables class. You can use the Composite method to draw one image on top of another image. You should give that a try. And below are some other comments on your current code.

1.
var bgDraw = new Drawables();
bgDraw.Draw(bgImage);
This does not draw the Image on the Drawables but it draws the drawables on your image. And because your Drawables collection is empty nothing will happen.

2.
images.Mosaic();
This returns an image that you seem to be ignoring. This image is the result of your Mosaic call.


3.
images.Write(frameMs, MagickFormat.Png);
This writes a png image and not a gif.