函数:replaceColor 颜色替换

函数功能:将图片上的指定颜色替换为其他颜色并返回结果

函数方法

img2,msg = image.replaceColor(img1,rgb1,rgb2,degree)

参数 类型 必填 说明
img1 usedata 需要操作的图片对象
rgb1 bumber 需要替换的颜色值
rgb2 bumber 替换后的颜色值
degree number 匹配度,不写默认为 0
返回值 类型 说明
img2 usedata/nil 颜色替换后的图片对象,失败显示空
msg nil/string 成功返回空,失败返回失败原因

函数用例

local image = require("tsimg")  
--将文件转换为图片对象
snapshot("replaceColor1.png", 0, 0, 100, 100)
local newImage = image.loadFile(userPath() .. "/res/replaceColor1.png")
--将黑色 * 0.8 至黑色 * 1.2 之间的颜色值替换成白色
local newImage1,msg = image.replaceColor(newImage,0xE0E0E0,0xffffff,80)
if image.is(newImage1) then
    --将图片对象转换成图片保存在 res 文件夹下    
    local boo,msg = image.saveToPngFile(newImage1,userPath() .. "/res/replaceColor2.png")
    dialog(boo and "保存成功" or "保存失败 : " .. msg)
else
    dialog(msg,3)
end

注意事项

  • 该函数设置的颜色仅对触动获取颜色值生效,并非修改图片上的实际颜色。
  • Android 仅支持引擎版本 v3.0.1 及其以上,支持标准版、企业版、小精灵。
  • 安卓普通版需要登录账号、购买 VIP 并且在调用过程中账号需要保持登录状态否则会导致调用失效。
  • iOS 仅支持专业版、企业版、小精灵。
  • Android 真机与模拟器 tsimg.so 文件不同,需要按照设备类型进行下载。
  • 点击 使用方法tsimg.so 下载 查看使用方法及下载地址。
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""