try this   
function getHealthColor() 
    local health = getElementHealth(localPlayer) 
         
    if (health) then 
        local g = (255/1000) * health 
        local r = 255 - g 
        local b = 0 
      
        return r, g, b 
    else 
        return 0, 255, 0 
    end 
end 
--------------------------------------------- 
  
  
local image = "textures/carState.png" 
local csr, csg, csb = getHealthColor() 
dxDrawImage(screenWidth - 30, screenHeight - 125, 24, 24, image, 0, 0, 0, tocolor(csr, csg, csb , 255), true)