Skip to main content

Update a Bitmap

Lua Automation IDE

The following code demonstrates how to update a Bitmap writing to it's individual pixels.

Lua

-- Check if our temporary directory exists
if directory.Exists("C:\\Temp") == false then
    ui.Log("C:\\Temp does not exist.  Please specify a valid directory")
	do return end
end

-- Creates a 128x128 PNG file with a green background
local bitmap = factory.Bitmap(128, 128)

-- Lua is a 1 index language but the underlying C# objects
-- are 0 index objects.
for x = 0, 127 do
	for y = 0, 127 do
		bitmap.SetPixel(x, y, "green")
	end
end

bitmap.SavePng("C:\\Temp\\green.png")
bitmap.Dispose()

-- Now, reload the bitmap from the file and update the upper portion of it to be white
local bitmap = factory.Bitmap("C:\\Temp\\green.png")

-- Lua is a 1 index language but the underlying C# objects
-- are 0 index objects.
for x = 0, 127 do
	for y = 0, 63 do
		bitmap.SetPixel(x, y, "white")
	end
end

bitmap.SavePng("C:\\Temp\\green-white.png")
bitmap.Dispose()
Last Modified: 07/06/2023