public IEnumerator CaptureScreenAndShare(object uiTexture) { bool toFriend = m_bToFriend; Rect rect; if (uiTexture is UIPanel) { rect = Utility.GetUIScreenRect((UIPanel)uiTexture); } else { rect = Utility.GetUIScreenRect((UIWidget)uiTexture); } yield return(new WaitForEndOfFrame()); Texture2D cutImage = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false); cutImage.ReadPixels(rect, 0, 0, false); cutImage.Apply(); const int MAX_WIDTH = 1920; const int MAX_HEIGHT = (int)(MAX_WIDTH / 1.7777777f); const int JPG_QUALITY = 100; const float Scaling = 0.8f; const int MAX_SIZE = 1024 * 1024 * 1; const int MIN_SIZE = 1024 * 32; if (cutImage.width > MAX_WIDTH || cutImage.height > MAX_HEIGHT) { float x = (float)MAX_WIDTH / cutImage.width; float y = (float)MAX_HEIGHT / cutImage.height; cutImage = Utility.ScaleTexture(cutImage, Mathf.Max(x, y)); } byte[] byt = cutImage.EncodeToJPG(JPG_QUALITY); //保存原图 while (byt.Length > MAX_SIZE) //最大1M { //图片太大,继续缩放 cutImage = Utility.ScaleTexture(cutImage, Scaling); byt = cutImage.EncodeToJPG(JPG_QUALITY); } string imgstr = "cutimage.jpg"; string path = RuntimeInfo.GetLocalPath(imgstr); System.IO.File.WriteAllBytes(path, byt); /* * //保存缩略图 * while (byt.Length > MIN_SIZE) //最大32 k * { * //图片太大,继续缩放 * cutImage = Utility.ScaleTexture(cutImage, Scaling); * byt = cutImage.EncodeToJPG(JPG_QUALITY); * } * string path = RuntimeInfo.GetLocalPath(imgstr); * System.IO.File.WriteAllBytes(path, byt); */ //NativeInterface.BeginShare(toFriend, ServerSetting.ShareTxt, path); SDKMgr.Instance.SDK.Share(path); yield break; }
bool SaveRes(MultiFileOK dd) { //验证crc DownResData drd = dd.Drd; if (drd.ResSize != dd.Data.Length) { LogMgr.Log("Res:" + drd.ResType + " 大小不匹配,localSize:" + dd.Data.Length + ", serverSize:" + drd.ResSize); return(false); } uint crc = Crc.Crc32(dd.Data, 0, dd.Data.Length); if (crc != drd.ResCrc) { LogMgr.Log("Res:" + drd.ResType + "资源检验失败, size:" + dd.Data.Length + ", localCrc:" + crc + ", serverCrc:" + drd.ResCrc); return(false); } System.Random rr = new System.Random(); int name = rr.Next(100, 10000); string tempFile = RuntimeInfo.GetLocalPath(drd.ResType + name.ToString() + "_temp.dat"); string path = RuntimeInfo.GetResPersistentPath(drd.ResType); try { File.Delete(tempFile); } catch { } try { File.Delete(path); } catch { } try { FileStream fsTemp = File.Create(tempFile); if (fsTemp == null) { LogMgr.Log("RES文件创建失败:" + drd.ResType); return(false); } //解压 fsTemp.Write(dd.Data, 0, dd.Data.Length); fsTemp.Flush(); fsTemp.Close(); fsTemp = null; LZMA.DecompressFile(tempFile, path); } catch (System.Exception e) { ReportException.Instance.AddException("文件解压失败:" + e.ToString()); } try { File.Delete(tempFile); } catch { } if (File.Exists(path) == false) { LogMgr.Log("RES文件解压失败:" + drd.ResType); return(false); } ResManager.Instance.VersionMgr.SetResVersion(drd.ResType, drd.ResCrc, drd.ResUnzipSize); return(ResManager.Instance.VersionMgr.SaveVersion()); }