public static Layer MergeWith(this Layer thisLayer, Layer otherLayer, string newName, Vector documentsSize) { thisLayer.GetCloser(otherLayer, out Layer xCloser, out Layer yCloser, out Layer xOther, out Layer yOther); // Calculate the offset to the other layer int offsetX = Math.Abs(xCloser.OffsetX + xCloser.Width - xOther.OffsetX); int offsetY = Math.Abs(yCloser.OffsetY + yCloser.Height - yOther.OffsetY); // Calculate the needed width and height of the new layer int width = xCloser.Width + offsetX + xOther.Width; int height = yCloser.Height + offsetY + yOther.Height; // Merge both layers into a bitmap WriteableBitmap mergedBitmap = BitmapUtils.CombineLayers((int)documentsSize.X, (int)documentsSize.Y, new Layer[] { thisLayer, otherLayer }); mergedBitmap = mergedBitmap.Crop(xCloser.OffsetX, yCloser.OffsetY, width, height); // Create the new layer with the merged bitmap Layer mergedLayer = new Layer(newName, mergedBitmap) { Offset = new Thickness(xCloser.OffsetX, yCloser.OffsetY, 0, 0) }; return(mergedLayer); }
private Surface CreateCombinedPreview(Layer selLayer, Layer[] layersToCombine) { var combined = BitmapUtils.CombineLayers(moveStartRect, layersToCombine, BitmapManager.ActiveDocument.LayerStructure); if (selLayer != null) { using var selSnap = selLayer.LayerBitmap.SkiaSurface.Snapshot(); combined.SkiaSurface.Canvas.DrawImage(selSnap, 0, 0, Surface.MaskingPaint); } return(combined); }
public void TestThatCombineLayersReturnsCorrectBitmapWithSamePixels() { Coordinates[] cords = { new Coordinates(0, 0) }; Layer[] layers = { new Layer("test", 2, 2), new Layer("test2", 2, 2) }; layers[0].SetPixels(BitmapPixelChanges.FromSingleColoredArray(cords, Colors.Green)); layers[1].SetPixels(BitmapPixelChanges.FromSingleColoredArray(cords, Colors.Red)); var outputBitmap = BitmapUtils.CombineLayers(layers, 2, 2); Assert.Equal(Colors.Red, outputBitmap.GetPixel(0, 0)); }
private static Surface CreateMaskedCombinedSurface(Layer[] layers, LayerStructure structure, Layer selLayer) { if (layers.Length == 0) { throw new ArgumentException("Can't combine 0 layers"); } selLayer.ClipCanvas(); Surface combined = BitmapUtils.CombineLayers(new Int32Rect(selLayer.OffsetX, selLayer.OffsetY, selLayer.Width, selLayer.Height), layers, structure); using SKImage snapshot = selLayer.LayerBitmap.SkiaSurface.Snapshot(); combined.SkiaSurface.Canvas.DrawImage(snapshot, 0, 0, Surface.MaskingPaint); return(combined); }
public void TestThatCombineLayersReturnsCorrectBitmap() { Coordinates[] cords = { new Coordinates(0, 0), new Coordinates(1, 1) }; Layer[] layers = { new Layer("test", 2, 2), new Layer("test2", 2, 2) }; layers[0].SetPixels(BitmapPixelChanges.FromSingleColoredArray(new[] { cords[0] }, Colors.Green)); layers[1].SetPixels(BitmapPixelChanges.FromSingleColoredArray(new[] { cords[1] }, Colors.Red)); WriteableBitmap outputBitmap = BitmapUtils.CombineLayers(2, 2, layers); Assert.Equal(Colors.Green, outputBitmap.GetPixel(0, 0)); Assert.Equal(Colors.Red, outputBitmap.GetPixel(1, 1)); }
public static Layer MergeWith(this Layer thisLayer, Layer otherLayer, string newName, PixelSize documentSize) { Int32Rect thisRect = new(thisLayer.OffsetX, thisLayer.OffsetY, thisLayer.Width, thisLayer.Height); Int32Rect otherRect = new(otherLayer.OffsetX, otherLayer.OffsetY, otherLayer.Width, otherLayer.Height); Int32Rect combined = thisRect.Expand(otherRect); Surface mergedBitmap = BitmapUtils.CombineLayers(combined, new Layer[] { thisLayer, otherLayer }); Layer mergedLayer = new Layer(newName, mergedBitmap, documentSize.Width, documentSize.Height) { Offset = new Thickness(combined.X, combined.Y, 0, 0), }; return(mergedLayer); }
/// <summary> /// Copies selection to clipboard in PNG, Bitmap and DIB formats. /// </summary> /// <param name="layers">Layers where selection is</param> /// <param name="selection"></param> /// <param name="originalImageWidth">Output </param> /// <param name="originalImageHeight"></param> public static void CopyToClipboard(Layer[] layers, Coordinates[] selection, int originalImageWidth, int originalImageHeight) { Clipboard.Clear(); WriteableBitmap combinedBitmaps = BitmapUtils.CombineLayers(layers, originalImageWidth, originalImageHeight); using (var pngStream = new MemoryStream()) { DataObject data = new DataObject(); var croppedBmp = BitmapSelectionToBmpSource(combinedBitmaps, selection); data.SetData(DataFormats.Bitmap, croppedBmp, true); //Bitmap, no transparency support PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(croppedBmp)); encoder.Save(pngStream); data.SetData("PNG", pngStream, false); //PNG, supports transparency Clipboard.SetImage(croppedBmp); //DIB format Clipboard.SetDataObject(data, true); } }