Snippet from a WPF app that produces an image where every pixel is a different color.
using System.Drawing; | |
using System.Drawing.Imaging; | |
using System.Windows; | |
namespace GenerateMultiColorImages | |
{ | |
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
} | |
private void Button_Click(object sender, RoutedEventArgs e) | |
{ | |
var imgHeight = 128; | |
var imgWidth = 768; | |
var bmp = new Bitmap(imgWidth, imgHeight); | |
var totalColors = 256*256*256; | |
var colorRequired = imgHeight * imgWidth; | |
var r = 0; | |
var g = 0; | |
var b = 0; | |
var skip = int.Parse((totalColors/colorRequired).ToString()) - 1; | |
for (var x = 0; x < imgWidth; x++) | |
{ | |
for (var y = 0; y < imgHeight; y++) | |
{ | |
bmp.SetPixel(x, y, Color.FromArgb(r, g, b)); | |
b += skip; | |
if (b > 255) | |
{ | |
b = b - 255; | |
g += 1; | |
} | |
if (g > 255) | |
{ | |
g = g - 255; | |
r += 1; | |
} | |
} | |
} | |
bmp.Save("generated.png", ImageFormat.Png); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment