add file open
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user