There's not much wrong there, just a typo.
you have set the variable window
Img but create an image in variable window
Image. After all you only use the empty window
Img.
Here is a slightly modified version
//~ windowImg = 1
windowSpr = 1
// set window properties
SetWindowTitle("Window")
SetWindowSize(1024, 1024, 0)
SetVirtualResolution(1024, 1024)
img = LoadImage("gem.png")
spr = CreateSprite(img)
SetSpriteVisible(spr,0)
SetSpriteAnimation(spr, 256, 256, 4)
frame = 0
windowImage = CreateRenderImage(256, 256, 0, 0)
CreateSprite(windowSpr, windowImage)
SetSpritePosition(windowSpr, 256, 256)
SetSyncRate(10, 1)
Do
SetRenderToImage(windowImage, 0)
ClearScreen()
SetSpriteVisible(spr, 1)
SetSpriteFrame(spr, frame)
DrawSprite(spr)
inc frame
if frame > 4 then frame = 1
SetSpriteVisible(spr, 0)
SetRenderToScreen()
sync()
//~ SetRenderToImage(1, 0)
//~ ClearScreen()
loop