Van B: The order of bytes has changed in AGK. It is RGBA, not BGRA like it was in DBPro.
This code maps all the colours into an array. Again, I have enclosed the hard work in a function, and exported a 10x10 section into a text file so that you can see what the data looks like.
I DO NOT recommend putting all of the data into an array, it is simply duplicating data. use the equations you see in the function to examine the pixel data in the memblock.
The output looks like this:
Line 45, Pixel 45 : 82,243,236,179
Line 45, Pixel 46 : 157,254,85,213
Line 45, Pixel 47 : 253,146,96,199
Line 45, Pixel 48 : 47,152,63,254
Line 45, Pixel 49 : 102,32,255,176
Line 45, Pixel 50 : 136,204,86,139
Line 45, Pixel 51 : 255,240,222,147
Line 45, Pixel 52 : 0,0,0,0
Line 45, Pixel 53 : 204,162,251,50
Line 45, Pixel 54 : 0,0,0,0
Line 45, Pixel 55 : 255,117,198,127
Line 46, Pixel 45 : 215,157,250,85
Line 46, Pixel 46 : 199,253,146,96
Line 46, Pixel 47 : 254,47,152,63
Line 46, Pixel 48 : 149,89,192,255
Line 46, Pixel 49 : 139,79,240,86
Line 46, Pixel 50 : 147,255,240,222
Line 46, Pixel 51 : 0,0,0,0
Line 46, Pixel 52 : 246,227,150,244
Line 46, Pixel 53 : 0,0,0,0
Line 46, Pixel 54 : 157,255,83,204
Line 46, Pixel 55 : 0,0,0,0
Line 47, Pixel 45 : 95,201,254,143
Line 47, Pixel 46 : 63,254,47,152
Line 47, Pixel 47 : 255,149,89,192
Line 47, Pixel 48 : 86,139,79,240
Line 47, Pixel 49 : 114,75,245,104
Line 47, Pixel 50 : 0,0,0,0
Line 47, Pixel 51 : 250,241,225,150
Line 47, Pixel 52 : 0,0,0,0
Line 47, Pixel 53 : 156,152,243,50
Line 47, Pixel 54 : 0,0,0,0
Line 47, Pixel 55 : 254,84,202,160
Line 48, Pixel 45 : 140,62,253,59
Line 48, Pixel 46 : 32,255,176,102
Line 48, Pixel 47 : 240,86,139,79
Line 48, Pixel 48 : 104,114,75,245
Line 48, Pixel 49 : 0,0,0,0
Line 48, Pixel 50 : 148,253,240,222
Line 48, Pixel 51 : 0,0,0,0
Line 48, Pixel 52 : 0,0,0,0
Line 48, Pixel 53 : 0,0,0,0
Line 48, Pixel 54 : 162,251,83,204
Line 48, Pixel 55 : 0,0,0,0
Line 49, Pixel 45 : 90,56,254,167
Line 49, Pixel 46 : 136,204,200,28
Line 49, Pixel 47 : 255,240,222,147
Line 49, Pixel 48 : 0,0,0,0
Line 49, Pixel 49 : 223,148,253,240
Line 49, Pixel 50 : 0,0,0,0
Line 49, Pixel 51 : 244,246,227,150
Line 49, Pixel 52 : 0,0,0,0
Line 49, Pixel 53 : 156,152,243,24
Line 49, Pixel 54 : 0,0,0,0
Line 49, Pixel 55 : 238,30,42,112
Line 50, Pixel 45 : 0,0,0,0
Line 50, Pixel 46 : 148,253,240,222
Line 50, Pixel 47 : 0,0,0,0
Line 50, Pixel 48 : 241,225,150,250
Line 50, Pixel 49 : 0,0,0,0
Line 50, Pixel 50 : 150,244,246,227
Line 50, Pixel 51 : 0,0,0,0
Line 50, Pixel 52 : 24,40,108,221
Line 50, Pixel 53 : 0,0,0,0
Line 50, Pixel 54 : 109,254,43,44
Line 50, Pixel 55 : 0,0,0,0
Line 51, Pixel 45 : 0,0,0,246
Line 51, Pixel 46 : 0,0,0,0
Line 51, Pixel 47 : 221,0,0,0
Line 51, Pixel 48 : 0,0,0,0
Line 51, Pixel 49 : 40,108,221,0
Line 51, Pixel 50 : 0,0,0,0
Line 51, Pixel 51 : 221,24,40,108
Line 51, Pixel 52 : 0,0,0,0
Line 51, Pixel 53 : 44,109,254,43
Line 51, Pixel 54 : 0,0,0,0
Line 51, Pixel 55 : 254,43,44,109
Line 52, Pixel 45 : 0,0,0,0
Line 52, Pixel 46 : 162,251,83,204
Line 52, Pixel 47 : 0,0,0,0
Line 52, Pixel 48 : 83,204,162,251
Line 52, Pixel 49 : 0,0,0,0
Line 52, Pixel 50 : 152,243,50,156
Line 52, Pixel 51 : 0,0,0,0
Line 52, Pixel 52 : 43,44,109,254
Line 52, Pixel 53 : 0,0,0,0
Line 52, Pixel 54 : 109,254,173,69
Line 52, Pixel 55 : 0,0,0,0
Line 53, Pixel 45 : 209,158,254,82
Line 53, Pixel 46 : 0,0,0,0
Line 53, Pixel 47 : 255,82,208,157
Line 53, Pixel 48 : 0,0,0,0
Line 53, Pixel 49 : 204,162,251,83
Line 53, Pixel 50 : 0,0,0,0
Line 53, Pixel 51 : 254,43,44,109
Line 53, Pixel 52 : 0,0,0,0
Line 53, Pixel 53 : 44,109,254,173
Line 53, Pixel 54 : 0,0,0,0
Line 53, Pixel 55 : 247,114,92,132
Line 54, Pixel 45 : 170,109,241,112
Line 54, Pixel 46 : 123,252,117,198
Line 54, Pixel 47 : 201,0,0,0
Line 54, Pixel 48 : 84,202,160,254
Line 54, Pixel 49 : 0,0,0,0
Line 54, Pixel 50 : 112,238,30,42
Line 54, Pixel 51 : 0,0,0,0
Line 54, Pixel 52 : 43,44,109,254
Line 54, Pixel 53 : 0,0,0,0
Line 54, Pixel 54 : 117,247,114,92
Line 54, Pixel 55 : 0,0,0,0
Line 55, Pixel 45 : 167,92,248,92
Line 55, Pixel 46 : 33,254,177,104
Line 55, Pixel 47 : 231,177,219,159
Line 55, Pixel 48 : 162,184,49,201
Line 55, Pixel 49 : 41,109,251,41
Line 55, Pixel 50 : 0,0,0,0
Line 55, Pixel 51 : 238,30,42,112
Line 55, Pixel 52 : 0,0,0,0
Line 55, Pixel 53 : 69,117,247,173
Line 55, Pixel 54 : 0,0,0,0
Line 55, Pixel 55 : 254,241,220,34
And this is the code:
SetScreenResolution(GetDeviceWidth(), GetDeviceHeight())
SetVirtualResolution(GetDeviceWidth(), GetDeviceHeight())
SetWindowSize(GetDeviceWidth(), GetDeviceHeight(),1)
type tColour
r as integer
g as integer
b as integer
a as integer
endtype
global arrColours as tColour[-1,1]
img = createImage()
spr = createSprite(img)
SetSpritePositionByOffset(spr, GetVirtualWidth() / 2, GetVirtualHeight() / 2)
getAllColours(img, arrColours)
// Main loop
while GetRawKeyPressed(27) = 0
print(ScreenFPS())
sync()
endwhile
function getAllColours(img, colour ref as tColour[][])
mb = CreateMemblockFromImage(img)
width = GetMemblockInt(mb,0)
height = GetMemblockInt(mb,4)
//resize the array
arrColours.length = height
for i = 0 to height
arrColours[i].length = width
next i
log("Image Width = " + str(GetImageWidth(img)))
log("Image Height = " + str(GetImageHeight(img)))
log("Width = " + str(width))
log("Height = " + str(height))
log("Array dimension 1 length = " + str(arrColours.length))
log("Array dimension 2 length = " + str(arrColours[0].length))
//get all the colours
for h = 0 to height - 1
for w = 0 to width - 1
log("h " + str(h) + " w " + str(w))
offset = 12 + (h * w * 4) + (w*4)
arrColours[h,w].r = GetMemblockbyte(mb, offset + (w))
arrColours[h,w].g = GetMemblockbyte(mb,offset + (w+1))
arrColours[h,w].b = GetMemblockbyte(mb,offset + (w+2))
arrColours[h,w].a = GetMemblockbyte(mb,offset + (w+3))
next w
next h
f = OpenToWrite("results.txt")
for h = 45 to 55
for w = 45 to 55
WriteLine(f,"Line " + str(h) + ", Pixel " + str(w) + " : " + str(arrColours[h,w].r) + "," + str(arrColours[h,w].g) + "," + str(arrColours[h,w].b) + "," + str(arrColours[h,w].a))
next w
next h
DeleteMemblock(mb)
endfunction
function createImage()
//Create some colours
global tempSpr as integer[100]
for i = 1 to 100
tempSpr[i] = createsprite(0)
SetSpriteSize(tempSpr[i], random(10,20), random(10,20))
SetSpriteColor(tempSpr[i],random(1,255),random(1,255),random(1,255),random(128,255))
SetSpritePositionByOffset(tempSpr[i],(GetVirtualWidth() / 2) - 50 + random(10,80), (GetVirtualHeight() / 2) - 50 + random(10,80))
next i
render()
img = getImage((GetVirtualWidth()/2) - 50, (GetVirtualHeight() / 2) - 50,100,100)
ClearScreen()
for i = 1 to 100
DeleteSprite(tempSpr[i])
next i
endfunction img
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt