public void Clone() { var original = new SimplePngImage(2, 3); original.SetPixel(0, 0, Color.Red); original.SetPixel(0, 1, Color.Green); original.SetPixel(0, 2, Color.Blue); original.SetPixel(1, 0, Color.White); original.SetPixel(1, 1, Color.Black); original.SetPixel(1, 2, Color.Purple); var bmp = original.Clone(); original.SetPixel(1, 2, Color.Cyan); Assert.Equal(Color.Red, bmp.GetPixel(0, 0)); Assert.Equal(Color.Green, bmp.GetPixel(0, 1)); Assert.Equal(Color.Blue, bmp.GetPixel(0, 2)); Assert.Equal(Color.White, bmp.GetPixel(1, 0)); Assert.Equal(Color.Black, bmp.GetPixel(1, 1)); Assert.Equal(Color.Purple, bmp.GetPixel(1, 2)); //bmp.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "png-clone.png")); var memStream = new MemoryStream(); bmp.Save(memStream); Assert.Equal(76, memStream.Length); Assert.Equal("89504E470D0A1A0A0000000D4948445200000002000000030802000000368849D60000001349444154789C63F8CFC0F0FF3F9068608080FF0D0C0D00D6C212940000000049454E44AE426082", BitConverter.ToString(memStream.ToArray()).Replace("-", "")); }
private static SimplePngImage GetExampleImageColor16() { var bmp = new SimplePngImage(8, 8); for (var x = 0; x < 4; x++) { for (var y = 0; y < 4; y++) { var r = (byte)((7 - x) * 64); var g = (byte)(y * 64); var b = (byte)(((x * 64) & 0xF0) | ((y * 64) >> 4)); bmp.SetPixel(x * 2 + 0, y * 2 + 0, Color.FromArgb(r, g, b)); bmp.SetPixel(x * 2 + 0, y * 2 + 1, Color.FromArgb(r, g, b)); bmp.SetPixel(x * 2 + 1, y * 2 + 0, Color.FromArgb(r, g, b)); bmp.SetPixel(x * 2 + 1, y * 2 + 1, Color.FromArgb(r, g, b)); } } //bmp.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "png-color-16.png")); return(bmp); }
public void ColorAlpha() { var bmp = new SimplePngImage(2, 3); Assert.Equal(2, bmp.Width); Assert.Equal(3, bmp.Height); bmp.SetPixel(0, 0, Color.Red); bmp.SetPixel(0, 1, Color.Green); bmp.SetPixel(0, 2, Color.Blue); bmp.SetPixel(1, 0, Color.White); bmp.SetPixel(1, 1, Color.Black); bmp.SetPixel(1, 2, Color.FromArgb(128, Color.Purple)); Assert.Equal(Color.Red, bmp.GetPixel(0, 0)); Assert.Equal(Color.Green, bmp.GetPixel(0, 1)); Assert.Equal(Color.Blue, bmp.GetPixel(0, 2)); Assert.Equal(Color.White, bmp.GetPixel(1, 0)); Assert.Equal(Color.Black, bmp.GetPixel(1, 1)); Assert.Equal(Color.FromArgb(128, Color.Purple), bmp.GetPixel(1, 2)); //bmp.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "png-color-transparency.png")); var memStream = new MemoryStream(); bmp.Save(memStream); Assert.Equal(80, memStream.Length); Assert.Equal("89504E470D0A1A0A0000000D4948445200000002000000030806000000B9EADE810000001749444154789C63F8CFC0F01F0418181A18800404FF6F6068680000700275140000000049454E44AE426082", BitConverter.ToString(memStream.ToArray()).Replace("-", "")); }
public void SaveOpen32() { var bmp = new SimplePngImage(2, 3); bmp.SetPixel(0, 0, Color.Red); bmp.SetPixel(0, 1, Color.Green); bmp.SetPixel(0, 2, Color.Blue); bmp.SetPixel(1, 0, Color.White); bmp.SetPixel(1, 1, Color.Black); bmp.SetPixel(1, 2, Color.FromArgb(128, Color.Purple)); var memStream = new MemoryStream(); bmp.Save(memStream); memStream.Position = 0; var bmp2 = new SimplePngImage(memStream); Assert.Equal(Color.Red.ToArgb(), bmp2.GetPixel(0, 0).ToArgb()); Assert.Equal(Color.Green.ToArgb(), bmp2.GetPixel(0, 1).ToArgb()); Assert.Equal(Color.Blue.ToArgb(), bmp2.GetPixel(0, 2).ToArgb()); Assert.Equal(Color.White.ToArgb(), bmp2.GetPixel(1, 0).ToArgb()); Assert.Equal(Color.Black.ToArgb(), bmp2.GetPixel(1, 1).ToArgb()); Assert.Equal(Color.FromArgb(128, Color.Purple).ToArgb(), bmp2.GetPixel(1, 2).ToArgb()); }
private static SimplePngImage GetExampleImageColor2() { var bmp = new SimplePngImage(8, 8); for (var x = 0; x < 8; x++) { for (var y = 0; y < 8; y++) { bmp.SetPixel(x, y, (x % 2 == y % 2) ? Color.Red : Color.Blue); } } //bmp.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "png-color-2.png")); return(bmp); }
public void MonoAlpha() { var bmp = new SimplePngImage(2, 2); Assert.Equal(2, bmp.Width); Assert.Equal(2, bmp.Height); bmp.SetPixel(0, 0, Color.Black); bmp.SetPixel(0, 1, Color.DarkGray); bmp.SetPixel(1, 0, Color.Gray); bmp.SetPixel(1, 1, Color.FromArgb(192, Color.White)); Assert.Equal(Color.Black, bmp.GetPixel(0, 0)); Assert.Equal(Color.DarkGray, bmp.GetPixel(0, 1)); Assert.Equal(Color.Gray, bmp.GetPixel(1, 0)); Assert.Equal(Color.FromArgb(192, Color.White), bmp.GetPixel(1, 1)); //bmp.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "png-mono-transparency.png")); var memStream = new MemoryStream(); bmp.Save(memStream); Assert.Equal(71, memStream.Length); Assert.Equal("89504E470D0A1A0A0000000D4948445200000002000000020804000000D8BFC5AF0000000E49444154789C6360F8DFF09F61E5FFFF0700F55FDCD50000000049454E44AE426082", BitConverter.ToString(memStream.ToArray()).Replace("-", "")); }
public void MonoBasic() { var bmp = new SimplePngImage(2, 2); Assert.Equal(2, bmp.Width); Assert.Equal(2, bmp.Height); bmp.SetPixel(0, 0, Color.Black); bmp.SetPixel(0, 1, Color.DarkGray); bmp.SetPixel(1, 0, Color.Gray); bmp.SetPixel(1, 1, Color.White); Assert.Equal(Color.Black, bmp.GetPixel(0, 0)); Assert.Equal(Color.DarkGray, bmp.GetPixel(0, 1)); Assert.Equal(Color.Gray, bmp.GetPixel(1, 0)); Assert.Equal(Color.White, bmp.GetPixel(1, 1)); //bmp.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "png-mono-basic.png")); var memStream = new MemoryStream(); bmp.Save(memStream); Assert.Equal(67, memStream.Length); Assert.Equal("89504E470D0A1A0A0000000D494844520000000200000002080000000057DD52F80000000A49444154789C6360686058F91F00384FDB7F0000000049454E44AE426082", BitConverter.ToString(memStream.ToArray()).Replace("-", "")); }
private static SimplePngImage GetExampleImageMonochrome256() { var bmp = new SimplePngImage(16, 16); for (var x = 0; x < 16; x++) { for (var y = 0; y < 16; y++) { var m = x << 4 | y; bmp.SetPixel(x, y, Color.FromArgb(m, m, m)); } } //bmp.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "png-mono-256.png")); return(bmp); }
private static SimplePngImage GetExampleImageColor256() { var bmp = new SimplePngImage(16, 16); for (var x = 0; x < 16; x++) { for (var y = 0; y < 16; y++) { var r = (byte)((15 - x) * 16); var g = (byte)(y * 16); var b = (byte)(((x * 16) & 0xF0) | ((y * 16) >> 4)); bmp.SetPixel(x, y, Color.FromArgb(r, g, b)); } } //bmp.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "png-color-256.png")); return(bmp); }
private static SimplePngImage GetExampleImageColor4() { var bmp = new SimplePngImage(8, 8); for (var x = 0; x < 2; x++) { for (var y = 0; y < 2; y++) { var r = (byte)((7 - x) * 129); var g = (byte)(y * 128); var b = (byte)(((x * 128) & 0xF0) | ((y * 128) >> 4)); for (var i = 0; i < 4; i++) { for (var j = 0; j < 4; j++) { bmp.SetPixel(x * 4 + i, y * 4 + j, Color.FromArgb(r, g, b)); } } } } //bmp.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "png-color-4.png")); return(bmp); }