获取EmuCore的OutputTex时,还会根据DrawCanvas的localscale,来纠正存档图片Y轴翻转的处理

This commit is contained in:
ALIENJACK\alien 2025-04-15 15:41:50 +08:00
parent 8e24f556af
commit 959956706f
2 changed files with 12 additions and 15 deletions
AxibugEmuOnline.Client/Assets/Script/AppMain

View File

@ -67,7 +67,7 @@ namespace AxibugEmuOnline.Client
{
var stateData = m_ingameUI.Core.GetStateBytes();
var tex = m_ingameUI.Core.OutputPixel;
var screenData = tex.ToJPG();
var screenData = tex.ToJPG(m_ingameUI.Core.DrawCanvas.transform.localScale);
m_savFile.Save(m_savFile.Sequecen, stateData, screenData);
}

View File

@ -55,29 +55,26 @@ namespace AxibugEmuOnline.Client
}
public static byte[] ToJPG(this Texture texture)
public static byte[] ToJPG(this Texture texture, Vector2 scale)
{
Texture2D outputTex = null;
if (texture is RenderTexture rt)
{
outputTex = ConvertFromRenderTexture(rt);
}
else if (texture is Texture2D)
{
outputTex = texture as Texture2D;
}
Texture2D outputTex = ConvertFromRenderTexture(texture, scale);
return outputTex.EncodeToJPG();
}
private static Texture2D ConvertFromRenderTexture(RenderTexture rt)
private static Texture2D ConvertFromRenderTexture(Texture src, Vector2 scale)
{
float offsetX = (scale.x < 0) ? 1 : 0;
float offsetY = (scale.y < 0) ? 1 : 0;
var offset = new Vector2(offsetX, offsetY);
// 创建临时RenderTexture并拷贝内容
RenderTexture tempRT = RenderTexture.GetTemporary(rt.width, rt.height, 0, RenderTextureFormat.ARGB32);
Graphics.Blit(rt, tempRT);
RenderTexture tempRT = RenderTexture.GetTemporary(src.width, src.height, 0, RenderTextureFormat.ARGB32);
Graphics.Blit(src, tempRT, scale, offset);
// 读取到Texture2D
Texture2D tex = new Texture2D(rt.width, rt.height, TextureFormat.RGBA32, false);
Texture2D tex = new Texture2D(src.width, src.height, TextureFormat.RGBA32, false);
RenderTexture.active = tempRT;
tex.ReadPixels(new Rect(0, 0, tempRT.width, tempRT.height), 0, 0);
tex.Apply();