PhotographSaveView.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. protected override void OnInit()
  14. {
  15. base.OnInit();
  16. packageName = UI_PhotographUI.PACKAGE_NAME;
  17. _ui = UI_PhotographSaveUI.Create();
  18. viewCom = _ui.target;
  19. isfullScreen = true;
  20. _ui.m_btnClose.onClick.Add(this.Hide);
  21. _ui.m_btnSave.onClick.Add(this.OnClickBtnSave);
  22. _ui.m_btnSavePhoto.onClick.Add(this.OnClickBtnSavePhoto);
  23. }
  24. protected override void OnShown()
  25. {
  26. base.OnShown();
  27. Texture2D tex = this.viewData as Texture2D;
  28. _ui.m_imgRes.texture = new NTexture(tex);
  29. float width = _ui.m_imgBorder.width;
  30. float height = width * tex.height / tex.width;
  31. _ui.m_imgRes.SetSize(width, height);
  32. _ui.m_imgBorder.SetSize(width, height + 12);
  33. }
  34. protected override void OnHide()
  35. {
  36. base.OnHide();
  37. }
  38. public override void Dispose()
  39. {
  40. if (_ui != null)
  41. {
  42. _ui.Dispose();
  43. _ui = null;
  44. }
  45. base.Dispose();
  46. }
  47. private void OnClickBtnSave()
  48. {
  49. Texture2D tex = this.viewData as Texture2D;
  50. byte[] bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
  51. string fileName = "wsj" + TimeHelper.ServerNowSecs + ".jpg";
  52. PhotographDataManager.Instance.SavePicturoToLocal(bytes, fileName);
  53. }
  54. private async void OnClickBtnSavePhoto()
  55. {
  56. Texture2D tex = this.viewData as Texture2D;
  57. byte[] bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
  58. string fileName = "wsj" + TimeHelper.ServerNowSecs + ".jpg";
  59. string[] rsp = await PoemPhotoSProxy.ReqTempPictureUrl(fileName);
  60. if (rsp == null) return;
  61. string code = PoemPhotoSProxy.PushToHWCloud(rsp[0], bytes);
  62. if (string.IsNullOrEmpty(code)) return;
  63. PoemPhotoSProxy.ReqAddTophoto(rsp[1], (int)PictureSourceType.PersonalAlbum).Coroutine();
  64. }
  65. }
  66. }