PhotographSaveView.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using ET;
  5. using FairyGUI;
  6. using UI.DressUp;
  7. using UnityEngine;
  8. namespace GFGGame
  9. {
  10. public class PhotographSaveView : BaseView
  11. {
  12. private UI_PhotographSaveUI _ui;
  13. private byte[] bytes;
  14. protected override void OnInit()
  15. {
  16. base.OnInit();
  17. packageName = UI_PhotographUI.PACKAGE_NAME;
  18. _ui = UI_PhotographSaveUI.Create();
  19. viewCom = _ui.target;
  20. isfullScreen = true;
  21. _ui.m_btnClose.onClick.Add(this.Hide);
  22. _ui.m_btnSave.onClick.Add(this.OnClickBtnSave);
  23. _ui.m_btnSavePhoto.onClick.Add(this.OnClickBtnSavePhoto);
  24. }
  25. protected override void OnShown()
  26. {
  27. base.OnShown();
  28. Texture2D tex = this.viewData as Texture2D;
  29. bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
  30. _ui.m_imgRes.texture = new NTexture(tex);
  31. float width = _ui.m_imgBorder.width;
  32. float height = width * tex.height / tex.width;
  33. _ui.m_imgRes.SetSize(width, height);
  34. _ui.m_imgBorder.SetSize(width, height + 12);
  35. }
  36. protected override void OnHide()
  37. {
  38. base.OnHide();
  39. }
  40. public override void Dispose()
  41. {
  42. if (_ui != null)
  43. {
  44. _ui.Dispose();
  45. _ui = null;
  46. }
  47. base.Dispose();
  48. }
  49. private void OnClickBtnSave()
  50. {
  51. // Texture2D tex = this.viewData as Texture2D;
  52. // byte[] bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
  53. string fileName = "wsj" + TimeHelper.ServerNowSecs + ".jpg";
  54. PhotographDataManager.Instance.SavePicturoToLocal(bytes, fileName);
  55. }
  56. private async void OnClickBtnSavePhoto()
  57. {
  58. if (PoemPhotoDataManager.Instance.PersonalPhotoInfos.Count >= GlobalCfgArray.globalCfg.maxPhotoCount)
  59. {
  60. PromptController.Instance.ShowFloatTextPrompt("照片数量已达上限");
  61. return;
  62. }
  63. // Texture2D tex = this.viewData as Texture2D;
  64. // byte[] bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
  65. string[] rsp = await PoemPhotoSProxy.ReqTempPictureUrl((int)PictureType.jpg);
  66. if (rsp == null) return;
  67. string code = PoemPhotoSProxy.PushToHWCloud(rsp[0], bytes);
  68. if (string.IsNullOrEmpty(code)) return;
  69. PoemPhotoSProxy.ReqAddTophoto(rsp[1], (int)PictureSourceType.PersonalAlbum).Coroutine();
  70. }
  71. }
  72. }