add file open

This commit is contained in:
2020-08-07 22:40:04 +08:00
parent c1e3f992aa
commit f9bedd2c62
115 changed files with 9835 additions and 1096 deletions

View File

@@ -118,7 +118,9 @@ function MyUtl.setIsHidePhone(val)
end
MyUtl.hidePhone = function(phone)
if not phone then return end
if not phone then
return
end
if not MyUtl.isHidePhone then
return phone
end
@@ -135,7 +137,8 @@ MyUtl.Images = {
[".PNG"] = true,
[".PDF"] = true,
[".BMP"] = true,
[".GIF"] = true,
[".TGA"] = true,
[".GIF"] = true
}
---public 是图片
@@ -143,4 +146,24 @@ MyUtl.isImage = function(path)
local extension = Path.GetExtension(path)
return MyUtl.Images[string.upper(extension)] or false
end
---@param oldTexture UnityEngine.Texture2D
MyUtl.CompressImage = function(imgPath, maxSize, quality)
if not File.Exists(imgPath) then
printe("文件不存在==".. imgPath)
return
end
-- int quality = 80;//图片压缩质量1-100
quality = quality or 75
local bytes = File.ReadAllBytes(imgPath)
---@type UnityEngine.Texture2D
local texture = Texture2D(2, 2)
ImageConversion.LoadImage(texture, bytes)
texture = MyFileOpen.ResizeTexture(texture, maxSize, MyFileOpen.ImageFilterMode.Average)
local newBytes = ImageConversion.EncodeToJPG(texture, quality)
return newBytes
end
return MyUtl