Microsoft Small Basic

Program Listing: KHD518
' Challenge 2016-10

title = "4096 Colors"
Init()
For y = cy To cy + th - 1
For x = cx To cx + tw - 1
color = GraphicsWindow.GetPixel(x, y)
len = Text.GetLength(color)
color = "#" + Text.GetSubText(color, len - 5, 1) + Text.GetSubText(color, len - 3, 1) + Text.GetSubText(color, len - 1, 1)
GraphicsWindow.SetPixel(x, y, color)
EndFor
EndFor

Sub Init
gw = 598 ' graphics window size
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
tw = 320 ' target size
th = 240
url = "https://social.msdn.microsoft.com/Forums/getfile/940109"
img = ImageList.LoadImage(url)
iw = ImageList.GetWidthOfImage(img) ' image size
ih = ImageList.GetHeightOfImage(img)
cx = (gw - tw) / 2 ' corner position
cy = (gh - th) / 2
GraphicsWindow.DrawResizedImage(img, cx, cy, tw, th)
GraphicsWindow.MouseMove = OnMouseMove
EndSub

Sub OnMouseMove
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
c = GraphicsWindow.GetPixel(mx, my)
GraphicsWindow.Title = title + " - " + c
EndSub