Most likely a bicycle, but since no solutions were proposed, he invented himself. Suddenly someone come in handy.
Here is the class of the canvas itself.
public class InfinityCanvas { List<ImageLayer> _layers { get; } = new List<ImageLayer>(); int _minLeftTopX = int.MaxValue; int _minLeftTopY = int.MaxValue; int _maxRightBottomX = int.MinValue; int _maxRightBottomY = int.MinValue; public void AddImage(Image image, Point position) { AddImage(image, position.X, position.Y); } public void AddImage(Image image, int x, int y) { _layers.Add(new ImageLayer(image, x, y)); if (_minLeftTopX >= x) _minLeftTopX = x; if (_minLeftTopY >= y) _minLeftTopY = y; if (_maxRightBottomX <= x + image.Width) _maxRightBottomX = x + image.Width; if (_maxRightBottomY <= y + image.Height) _maxRightBottomY = y + image.Height; } public Image GetResult() { if (_layers.Count == 0) { var b = new Bitmap(1, 1); return b; } var res = new Bitmap(_maxRightBottomX - _minLeftTopX, _maxRightBottomY - _minLeftTopY); var g = Graphics.FromImage(res); for (var i = 0; i < _layers.Count; i++) { var lay = _layers[i]; g.DrawImage(lay.Image, lay.LeftTopX - _minLeftTopX, lay.LeftTopY - _minLeftTopY, lay.Image.Width, lay.Image.Height); } return res; } }
Here is the layer class
class ImageLayer { public Image Image { get; set; } public int LeftTopX { get; set; } public int LeftTopY { get; set; } public ImageLayer(Image image, int x, int y) { Image = image; LeftTopX = x; LeftTopY = y; } }
Here we use
var ic = new InfinityCanvas(); ic.AddImage(someImage, -100, -100); ic.AddImage(someImage, someImage.Width, someImage.Height); ic.GetResult().Save("1.png");
The result is a picture in the upper left and lower right corners of which the image is contained in someImage . The distance between the images is 100 in both axes.