private static void ImportFrameAs <TPixel>(ImageFrameCollection source, ImageFrameCollection destination, int index) where TPixel : struct, IPixel <TPixel> { using (Image temp = source.CloneFrame(index)) { using (Image <TPixel> temp2 = temp.CloneAs <TPixel>()) { destination.AddFrame(temp2.Frames.RootFrame); } } }
public void CloneFrame <TPixel>(TestImageProvider <TPixel> provider) where TPixel : struct, IPixel <TPixel> { using (Image <TPixel> img = provider.GetImage()) { ImageFrameCollection nonGenericFrameCollection = img.Frames; nonGenericFrameCollection.AddFrame(new ImageFrame <TPixel>(Configuration.Default, 10, 10)); // add a frame anyway using (Image cloned = nonGenericFrameCollection.CloneFrame(0)) { Assert.Equal(2, img.Frames.Count); var expectedClone = (Image <TPixel>)cloned; expectedClone.ComparePixelBufferTo(img.GetPixelSpan()); } } }
public void ExtractFrame <TPixel>(TestImageProvider <TPixel> provider) where TPixel : struct, IPixel <TPixel> { using (Image <TPixel> img = provider.GetImage()) { var sourcePixelData = img.GetPixelSpan().ToArray(); ImageFrameCollection nonGenericFrameCollection = img.Frames; nonGenericFrameCollection.AddFrame(new ImageFrame <TPixel>(Configuration.Default, 10, 10)); using (Image cloned = nonGenericFrameCollection.ExportFrame(0)) { Assert.Equal(1, img.Frames.Count); var expectedClone = (Image <TPixel>)cloned; expectedClone.ComparePixelBufferTo(sourcePixelData); } } }
public void CloneFrame <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { using (Image <TPixel> img = provider.GetImage()) { ImageFrameCollection nonGenericFrameCollection = img.Frames; nonGenericFrameCollection.AddFrame(new ImageFrame <TPixel>(Configuration.Default, 10, 10)); // add a frame anyway using (Image cloned = nonGenericFrameCollection.CloneFrame(0)) { Assert.Equal(2, img.Frames.Count); var expectedClone = (Image <TPixel>)cloned; Assert.True(img.DangerousTryGetSinglePixelMemory(out Memory <TPixel> imgMem)); expectedClone.ComparePixelBufferTo(imgMem); } } }
public void ExtractFrame <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { using (Image <TPixel> img = provider.GetImage()) { Assert.True(img.DangerousTryGetSinglePixelMemory(out Memory <TPixel> imgMem)); TPixel[] sourcePixelData = imgMem.ToArray(); ImageFrameCollection nonGenericFrameCollection = img.Frames; nonGenericFrameCollection.AddFrame(new ImageFrame <TPixel>(Configuration.Default, 10, 10)); using (Image cloned = nonGenericFrameCollection.ExportFrame(0)) { Assert.Equal(1, img.Frames.Count); var expectedClone = (Image <TPixel>)cloned; expectedClone.ComparePixelBufferTo(sourcePixelData.AsSpan()); } } }