This article is about pixel in Microsoft Small Basic language.

What is a Pixel

A pixel is the smallest element of a digital picture.  An abbreviation px is used for pixels as a measure of resolution.  Default GraphicsWindow size is 624 pixels wide and 441 pixels high.  In HTML (CSS), 1 px is defined as 1/96 of 1 in (inch).

Operations for Pixels

There are following two operations in GraphicsWindow object.  Note that pixels in TextWindow can not be controlled:

  • GetPixel - gets the color of the pixel
  • SetPixel - draws the pixel


The following code gets the color where the mouse is clicked and shows it in the title.  This code shows "#000000" which means black.  But the GraphicsWindow is white.  Why?  This is because GetPixel operation returns foreground color.  By default, background color is white and foreground color is transparent black.  So, GetPixel returns black.  For more detail about these layers, see this article.  It also describes the reason why GetPixel can not get Shapes or Controls color.

GraphicsWindow.MouseDown = OnMouseDown
Sub OnMouseDown
  x = GraphicsWindow.MouseX
  y = GraphicsWindow.MouseY
  color = GraphicsWindow.GetPixel(x, y)
  GraphicsWindow.Title = color


Following code sets random color to random pixel in GraphicsWindow:

GraphicsWindow.BackgroundColor = "Black"
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
While "True"
  x = Math.GetRandomNumber(gw) - 1
  y = Math.GetRandomNumber(gh) - 1
  color = GraphicsWindow.GetRandomColor()
  GraphicsWindow.SetPixel(x, y, color)

Sample Programs

Following programs use GetPixel and SetPixel operations:

Known Issues

When a published program runs in web browser, following issues may occur.

See Also

Other Resources

Other Languages