Skip to content

Instantly share code, notes, and snippets.

@jldubz
Created March 26, 2019 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jldubz/745dd221cd2e888abf83b9eb27269946 to your computer and use it in GitHub Desktop.
Save jldubz/745dd221cd2e888abf83b9eb27269946 to your computer and use it in GitHub Desktop.
Draw directly to a canvas in Android using a matrix of boolean values for black or white pixels
var canvas = new Canvas();
canvas.SetViewport(256, 256);
var bitMatrix = new bool[256][]; //bool[256][256]
//Generate the bitMatrix
//...
var blackPaint = new Paint {Color = Color.Black};
var whitePaint = new Paint {Color = Color.White};
for (var x = 0; x < 256; x++) {
for (var y = 0; y < 256; y++) {
canvas.DrawPoint(x,y, bitMatrix[x][y] ? blackPaint : whitePaint);
}
}
_image.SetImageBitmap(bitmap);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment