压缩图片bug解决

This commit is contained in:
CaiYanPeng 2021-11-22 09:51:17 +08:00
parent 3083224ee6
commit 9570334e25
5 changed files with 25 additions and 6 deletions

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; }

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("成功");

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);

View File

@ -6,8 +6,8 @@ EditorBuildSettings:
serializedVersion: 2
m_Scenes:
- enabled: 1
path: Assets/Scenes/Login-Mobile.unity
guid: 4be878da00cf764499988cf403faf94d
path: Assets/Scenes/Login.unity
guid: 6dce3e17997730b4492f91dd8fede429
- enabled: 1
path: Assets/Scenes/MainScene.unity
guid: ab586a3c1bacd4a48a55178eb06fe0cc

View File

@ -180,7 +180,7 @@ PlayerSettings:
Android: com.ZhiXingPai.PowerFunUnity
buildNumber:
iPhone: 2.0.7.0
AndroidBundleVersionCode: 9
AndroidBundleVersionCode: 10
AndroidMinSdkVersion: 24
AndroidTargetSdkVersion: 30
AndroidPreferredInstallLocation: 1