压缩图片bug解决

This commit is contained in:
Caiyanpeng committed 2021-11-22 09:51:17 +08:00
1 parent 3083224ee6
commit 9570334e25
5 files changed
+25 -6

No files matched your search

+1 -1
View File
@@ -54,7 +54,7 @@ public static class App
public static IDictionary<string, Texture> TextureCache = new Dictionary<string, Texture>();
public static Texture CurrentUserHeadTexture;
public static RouteResult routeResult;//骑行记录向骑行场景传值
public static Texture DefaultRotateTexture;
public static Texture DefaultRotateTexture { get; set; }
//全局用 输入框或者下拉框修改标志位
public static bool isChanged { get; set; }
public static string notifyContent { get; internal set; }
+1 -1
View File
@@ -611,7 +611,7 @@ public class LoginController : BaseScene
//}
Debug.Log(JsonConvert.SerializeObject(locationInfo));
var i = await ConfigHelper.thirdPartApi.GetMapImage(locationInfo);
var t = new Texture2D(4, 4,TextureFormat.DXT5, false);
var t = new Texture2D(2, 2, TextureFormat.DXT5, false);
if (t.LoadImage(Utils.StreamToBytes(i)))
{
Debug.Log("成功");
+20 -1
View File
@@ -432,10 +432,29 @@ namespace Assets.Scripts
}
/*获取最顶层对象*/
/*Texture相关*/
public static Texture2D DeCompress(this Texture2D source)
{
RenderTexture renderTex = RenderTexture.GetTemporary(
source.width,
source.height,
0,
RenderTextureFormat.Default,
RenderTextureReadWrite.Linear);
Graphics.Blit(source, renderTex);
RenderTexture previous = RenderTexture.active;
RenderTexture.active = renderTex;
Texture2D readableText = new Texture2D(source.width, source.height);
readableText.ReadPixels(new Rect(0, 0, renderTex.width, renderTex.height), 0, 0);
readableText.Apply();
RenderTexture.active = previous;
RenderTexture.ReleaseTemporary(renderTex);
return readableText;
}
public static void WriteTextureToPlayerPrefs(string tag, Texture2D tex)
{
// if texture is png otherwise you can use tex.EncodeToJPG().
byte[] texByte = tex.EncodeToPNG();
byte[] texByte = tex.DeCompress().EncodeToJPG();
// convert byte array to base64 string
string base64Tex = System.Convert.ToBase64String(texByte);