Displaying part of an image?

BlitzMax Forums/BlitzMax Beginners Area/Displaying part of an image?

What about a simple solution like this ?
Strict

Graphics 640, 480, 0
SetClsColor 166, 166, 166

'make us an image for demonstration purpose
SetBlend SOLIDBLEND
SetMaskColor 0, 0, 0
SetColor 255, 0, 0
DrawRect 0, 0, 64, 64
SetColor 255, 255, 255
DrawRect 64, 0, 64, 64
SetColor 0, 0, 255
DrawRect 0, 64, 64, 64
SetColor 255, 255, 0
DrawRect 64, 64, 64, 64

Local curImgHandle:TImage =CreateImage(128, 128, 1, DYNAMICIMAGE | MASKEDIMAGE)
GrabImage curImgHandle, 0, 0

SetBlend ALPHABLEND
SetColor 255, 255, 255

Local offsetX:Int =47
Local offsetY:Int =37
Repeat

  Cls

  DrawText "original image", 75, 80
  DrawImage curImgHandle, 75, 100

  DrawText "image drawn as 32 x 32 from :" +offsetX +", "+offsetY, 250, 80
  DrawText "(use arrow keys and home to change display)", 250, 150

  SetViewport 250, 100, 32, 32 'desired location and with of images displayed part
  DrawImage curImgHandle, 250 -offsetX, 100 -offsetY
  'change displayed part of image
  If KeyDown(KEY_LEFT) Then
    offsetX :-1
  ElseIf KeyDown(KEY_RIGHT) Then
    offsetX :+1
  ElseIf KeyDown(KEY_UP) Then
    offsetY :-1
  ElseIf KeyDown(KEY_DOWN) Then
    offsetY :+1
  ElseIf KeyDown(KEY_HOME) Then
    offsetX =47
    offsetY =37
  End If
  offsetX =Abs(offsetX Mod (128 -32))
  offsetY =Abs(offsetY Mod (128 -32))

  SetViewport 0, 0, 640, 480

  Flip

Until KeyHit(KEY_ESCAPE)