The
Get Image command will copy anything within the defined area that has been Drawn to the Screen and create a new Image with it.
If we want to use an image we've already created and saved as a PNG or JPG then we'd use the
Load Image command.
Now keep in mind that if we don't precisely specify a Hard Disk Location (such-as "C:\Windows\Web\Wallpaper\Theme1\img1.jpg"., which is a real location and image that is on every Windows PC since Windows Vista... although the image will be different from release to release) well then the Command will assume that you mean a location from wherever the Runtime.exe (or whatever you chose to rename it) is running from.
So, if I copied Runtime.exe to C:\myApplication\ then if I called Load Image 1, "img1.jpg" ... it would EXPECT the image to be located at C:\myApplication\img1.jpg
With Get Image., we don't have to worry about a location on Physical or Network Storage; because well we're just Copying whatever is On-Screen.
For example:
#Constant True -1
#Constant False 0
#Constant Enable 1
#Constant Disable 0
Set Display Mode 1280, 1024, 32
Sync On : Sync Rate 60
// Load Image from Storage
Load Image "C:\Windows\Web\Wallpaper\Theme1\img1.jpg", 1
// Paste it to Screen, so we can grab a section
Paste Image 1, 0, 0, Disable
// Grab an Interesting part
Get Image 2, 450, 670, 650, 850, 1
Global bSwitchImage As Integer
Global bKeyHeld As Boolean
Global AppRunning As Integer : AppRunning = True
Repeat
Cls
// When Space is Pressed switch the Displayed Image
If SpaceKey( )
If bKeyHeld = False
bSwitchImage = bSwitchImage Not bSwitchImage
EndIf
bKeyHeld = True
Else
bKeyHeld = False
EndIf
// Simple Finite State Machine
Select bSwitchImage
Case True:
Paste Image 2, 0, 0, Disable
EndCase
Case False:
Paste Image 1, 0, 0, Disable
EndCase
EndSelect
// A Quick and Dirty: If Any Key OTHER than Spacebar Pressed, Quit the Progam
If Scancode() <> 57 And Scancode() <> 0
AppRunning = False
EndIf
Sync
Until AppRunning = False
// Clean Up
Delete Image 1
Delete Image 2
End
Now we can do some interesting things with the Get Image Command... like say we want to make an Animated Image, for example Super Mario Running.
Well we could use this image (right-click > save-as "mario.jpg")
#Constant True -1
#Constant False 0
#Constant Enable 1
#Constant Disable 0
Set Display Mode 640, 480, 32
Sync On : Sync Rate 60
// Load the Mario Sprite Sheet
Load Image "Mario.png", 1
// Paste it so we can Get each Image Frame
Paste Image 1, 0, 0, Disable
// We use "Pink" as our Transparency Colour
// And we have to set this BEFORE we Grab the Images
Set Image Colorkey 163, 73, 164
// Get each Frame of Animation
Get Image 10, 48 * 0, 0, 48 * 1, 48, 1
Get Image 11, 48 * 1, 0, 48 * 2, 48, 1
Get Image 12, 48 * 2, 0, 48 * 3, 48, 1
Get Image 13, 48 * 3, 0, 48 * 4, 48, 1
Type Timer_t
Old As Dword
New As Dword
Delta As Dword
Counter As Dword
EndType
Global AnimationTimer As Timer_t
Global Frame As Dword : Frame = 10
Global AppRunning As Boolean : AppRunning = True
Repeat
Cls
// Update Timer
AnimationTimer.Old = AnimationTimer.New
AnimationTimer.New = Timer()
AnimationTimer.Delta = AnimationTimer.New - AnimationTimer.Old
Inc AnimationTimer.Counter, AnimationTimer.Delta
// Every 1/8th Second
If AnimationTimer.Counter > 125
// Reset the Counter
AnimationTimer.Counter = 0
// Select the Next Frame
Inc Frame
If Frame > 13 Then Frame = 10
EndIf
// Paste Frame
Paste Image Frame, 0, 0, Enable
// Quit if any key is pressed
If Scancode() <> 0
AppRunning = False
EndIf
Sync
Until AppRunning = False
Delete Image 1
Delete Image 10
Delete Image 11
Delete Image 12
Delete Image 13
End
This will provide an Animated "Mario"... of course Images themselves are actually quite limiting in terms of what we can do with them without delving into complicated pixel manipulation.
Also they're not exactly a "Fast" approach, as you're not using any Hardware Acceleration; it's instead using your CPU to handle everything.
What's much better is to use those Images for Sprites., as with a Sprite... well aside from being Hardware Accelerate by your Graphics Card., you have much more you can do with them.
But I'll let you figure out how those work, this should be a simple enough primer for Images.