public void CreateMemoryBitmap() { var m1 = new MemoryBitmap <UInt32>(16, 16, Pixel.BGRA32.Format); m1.SetPixels(0xff406040); m1.Save(new AttachmentInfo("result.png")); }
public void TestTransform(bool useBilinear) { var src = LoadShannonImage().OfType <Pixel.BGR24>(); src.Save(new AttachmentInfo("input.png")); var filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\cat.png"); var cat00 = MemoryBitmap .Load(filePath, Codecs.GDICodec.Default) .OfType <Pixel.BGRA32>(); filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\QRCode.png"); var qrcode = MemoryBitmap .Load(filePath, Codecs.GDICodec.Default) .OfType <Pixel.BGRA32>(); var x = Matrix3x2.CreateScale(0.75f, 0.75f) * Matrix3x2.CreateRotation(0.25f); x.Translation = new Vector2(20, 20); Matrix3x2.Invert(x, out var xx); var dst = new MemoryBitmap <Pixel.BGR24>(512, 512); using (PerformanceBenchmark.Run(t => TestContext.WriteLine($"Transform {(int)t.TotalMilliseconds}ms"))) { dst.AsSpanBitmap().SetPixels(xx, src.AsSpanBitmap(), useBilinear); } for (float r = 0.1f; r < 1; r += 0.2f) { // 1st API var xform = Matrix3x2.CreateRotation(r) * Matrix3x2.CreateTranslation(50, 15); xform = Matrix3x2.CreateTranslation(-50, -50) * xform * Matrix3x2.CreateTranslation(50, 50); xform = xform * Matrix3x2.CreateScale(3, 3); dst.AsSpanBitmap().SetPixels(xform, cat00.AsSpanBitmap(), useBilinear, r); DrawBounds(dst, cat00.Bounds, xform, Colors.Red); // 2nd API xform *= Matrix3x2.CreateTranslation(0, 150); dst.AsSpanBitmap().SetPixels(xform, cat00.AsSpanBitmap(), useBilinear, r); DrawBounds(dst, cat00.Bounds, xform, Colors.Red); } dst.AsSpanBitmap().SetPixels(Matrix3x2.CreateScale(3), cat00.AsSpanBitmap(), useBilinear); dst.AsSpanBitmap().SetPixels(Matrix3x2.CreateScale(-.6f) * Matrix3x2.CreateTranslation(40, 200), cat00.AsSpanBitmap(), useBilinear); dst.AsSpanBitmap().SetPixels(Matrix3x2.CreateScale(.3f) * Matrix3x2.CreateRotation(1) * Matrix3x2.CreateTranslation(150, 300), qrcode.AsSpanBitmap(), useBilinear); dst.Save(new AttachmentInfo("transformed.png")); }
public void LoadKinect2ColorFrame() { TestContext.CurrentContext.AttachFolderBrowserShortcut(); var src = MemoryBitmap <ushort> .Load(ResourceInfo.From("Kinect2Color.InteropBmp")); var dst = new MemoryBitmap <Pixel.BGR24>(src.Width, src.Height); dst.AsSpanBitmap().SetPixelsFromYUY2(src); dst.Save(AttachmentInfo.From("kinect2color.jpg")); }
public void TestTransformWithConversion() { var src = LoadShannonImage().OfType <Pixel.BGR24>(); src.Save(new AttachmentInfo("input.png")); var dst = new MemoryBitmap <Pixel.RGB96F>(512, 512); dst.AsSpanBitmap().SetPixels(Matrix3x2.CreateScale(0.7f), src.AsSpanBitmap(), true, 1); dst.Save(new AttachmentInfo("transformed.png")); }
public void CopyPixelsWithStride() { var m1 = new MemoryBitmap <UInt32>(16, 16, Pixel.BGRA32.Format); m1.SetPixel(0, 0, 0xff00ff00); m1.SetPixel(0, 1, 0xffff00ff); var m2 = new MemoryBitmap <UInt32>(16, 16, Pixel.BGRA32.Format, 17 * 4); m2.SetPixels(0, 0, m1); m2.Save(new AttachmentInfo("result.png")); Assert.AreEqual(0xff00ff00, m2.GetPixel(0, 0)); Assert.AreEqual(0xffff00ff, m2.GetPixel(0, 1)); }
public void ResizeTest1(int dstSize) { var src = LoadShannonImage(); var dst = new MemoryBitmap(dstSize, dstSize, Pixel.BGR24.Format, dstSize * 3 + 17); BitmapsToolkit.FitPixels(src, dst, (0, 1)); var sw = System.Diagnostics.Stopwatch.StartNew(); BitmapsToolkit.FitPixels(src, dst, (0, 1)); var elapsed = sw.Elapsed; TestContext.WriteLine($"{elapsed.Milliseconds}ms {elapsed.Ticks}ticks"); src.Save(AttachmentInfo.From("input.png")); dst.Save(AttachmentInfo.From($"output_{dstSize}.png")); }
public void SetPixels() { var dst = new MemoryBitmap <Byte>(16, 16, Pixel.Luminance8.Format); var src = new MemoryBitmap <Byte>(8, 8, Pixel.Luminance8.Format); src.SetPixels(50); dst.SetPixels(4, 4, src); src.SetPixels(255); dst.SetPixels(-4, -4, src); src.SetPixels(130); dst.SetPixels(12, -4, src); src.SetPixels(255); dst.SetPixels(12, 12, src); src.SetPixels(70); dst.SetPixels(-4, 12, src); dst.SetPixels(-50, 0, src); dst.Save(new AttachmentInfo("Result.png")); }
public static System.IO.FileInfo WriteImage(this AttachmentInfo ainfo, MemoryBitmap image) { return(ainfo.WriteObject(f => image.Save(f))); }