PhotographSaveView.cs 3.1 KB

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