Created
November 2, 2011 21:02
-
-
Save einarwh/1334908 to your computer and use it in GitHub Desktop.
Create a pix-it image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Image CreateImage(PixItData data) | |
{ | |
int width = data.PixelSize * data.PixelsWide; | |
int height = data.PixelSize * data.PixelsHigh; | |
var image = new Bitmap(width, height); | |
using (Graphics g = Graphics.FromImage(image)) | |
{ | |
if (data.Background.HasValue) | |
{ | |
Color bgColor = data.Background.Value; | |
using (var brush = new SolidBrush(bgColor)) | |
{ | |
g.FillRectangle(brush, 0, 0, | |
data.PixelSize * data.PixelsWide, | |
data.PixelSize * data.PixelsHigh); | |
} | |
} | |
foreach (Color color in data.Data.Keys) | |
{ | |
using (var brush = new SolidBrush(color)) | |
{ | |
foreach (Pixel p in data.Data[color]) | |
{ | |
g.FillRectangle(brush, | |
p.X*data.PixelSize, | |
p.Y*data.PixelSize, | |
data.PixelSize, | |
data.PixelSize); | |
} | |
} | |
} | |
} | |
return image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment