c# - How to draw in WPF by pixel -


necessary draw pixels array data (large). how can that?

i tried canvas , rectangle on - computer hanged himself ... tried following options below (drawingcontext) - computer still hangs himself, little bit less.

please recommend options least load on computer. int width = 800; - size of array (large!!!) int size = 1; - desirable able make fragment not 1 several pixels

protected override void onrender(system.windows.media.drawingcontext drawingcontext)         {             random rnd = new random();             int width = 800;             int size = 1;             celltype[,] types = new celltype[width, width];             (int = 0; < width; i++)             {                 (int j = 0; j < width; j++)                 {                     int r = rnd.next(0, 100);                     if (r >= 70) types[j,i] = celltype.isoccupied;                     else types[j, i] = celltype.isempty;                 }             }               (int = 0; < width; i++)             {                 (int j = 0; j < width; j++)                 {                     brush brush = brushes.black;                      switch (types[j, i])                     {                         case celltype.isempty: brush = brushes.green;                             break;                         case celltype.isoccupied: brush = brushes.black;                             break;                     }                      drawingcontext.drawrectangle(brush,                     new pen(brush, 1),                     new rect(j * size, * size, size, size));                 }             }              base.onrender(drawingcontext);         } 

for how long freeze? couple of years ago did quite similar in silverlight. bit slow still acceptable. try using writeablebitmap setpixel or fillrectangle methods, please keep in mind drawing pixel pixel in loop take time.

forgot mention setpixel , fillrectangle may need writeablebitmapex, available here: http://writeablebitmapex.codeplex.com/


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -