(AGK version: 108.13)
Submitted: 2013-06-14 06:54:05
// load the image into memory and create a memblock from it
image = LoadImage("my_image.jpg")
memblock = CreateMemblockFromImage(image)

// get the meta data of the image
width = GetMemblockInt(memblock, 0)
height = GetMemblockInt(memblock, 4)
size = GetMemblockSize(memblock)

// we start at 12 because the first 12 bytes are taken up with meta data and so this is where the bitmap begins
// we continue until size - 1 because memblocks start as index 0 and so position size is not part of the memblock
// we step 4 each time as each pixel is represented by four bytes of data (red, green, blue, alpha)
for c = 12 to size - 1 step 4
    // each color byte is inverted
    SetMemblockByte(memblock, c, 255 - GetMemblockByte(memblock, c))
    SetMemblockByte(memblock, c + 1, 255 - GetMemblockByte(memblock, c + 1))
    SetMemblockByte(memblock, c + 2, 255 - GetMemblockByte(memblock, c + 2))
    // the alpha (position c + 3) is ignored because we don't want to invert that
next c

// create a new image and sprite from the inverted memblock (the source image is unaffected)
invertedColorImage = CreateImageFromMemblock(memblock)
sprite = CreateSprite(invertedColorImage)
SetSpriteSize(sprite, 100, -1)

// display the inverted image
do
    Sync()
loop
Help make AGK better by submitting an example for this command!
(All examples are subject to approval)
Login to post an example of your own.