Skip to content

lcd.drawBitmap

since 1.1.0

Draw a bitmap.

lcd.drawBitmap(x, y, bitmap[, w[, h]])

Parameters

Name Type Required Description
x number yes X coordinate
y number yes Y coordinate
bitmap Bitmap yes bitmap
w number optional (default 0) the width of the bitmap displayed
h number optional (default 0) the height of the bitmap display

Returns

Nothing.

Examples

local LOGO = lcd.loadBitmap("gfx/logo.png")

local function paint(widget)
  local w, h = lcd.getWindowSize()
  if not LOGO then return end
  lcd.drawBitmap(0, 0, LOGO)                 -- natural size
  lcd.drawBitmap(w - 64, 0, LOGO, 64, 64)    -- scaled into a 64x64 box
end

Scaling at draw time is convenient, but an image that is always shown small should be stored small: the decoded size is what costs RAM.

Used in

Real-world usage

Called 39 times across 7 open-source Ethos Lua projects. A few short excerpts:
lcd.drawBitmap(img_x, img_y, bitmapPtr, img_w, img_h)

src/dashx/widgets/dashboard/lib/utils.lua:948

if not pcall(lcd.drawBitmap, x, y, bmp, w, h) then lcd.drawBitmap(x, y, bmp) end

src/inav-dashboard/render/gps_lock.lua:64

lcd.drawBitmap(math.floor(imgX + 0.5), math.floor(imgY + 0.5), bitmap, math.floor(imgW + 0.5), math.floor(imgH + 0.5))

src/rfsuite/widgets/dashboard/context.lua:1866