In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how Unity screenshots in any area to create Sprite, the article is very detailed, has a certain reference value, interested friends must read it!
The method of capturing full-screen still frames by Unity is relatively simple. It is not discussed here. The most important method used to take screenshots in a specified area is to read screen pixels:
/ / Abstract: / / Read pixels from screen into the saved texture data. / Parameter: / / source: / / Rectangular region of the view to read from. Pixels are read from current render / / target. / destX: / / Horizontal pixel position in the texture to place the pixels that are read. / destY: / / Vertical pixel position in the texture to place the pixels that are read. / recalculateMipMaps: / / Should the texture's mipmaps be recalculated after reading? Public void ReadPixels (Rect source, int destX, int destY, [DefaultValue ("true")] bool recalculateMipMaps); [ExcludeFromDocs] public void ReadPixels (Rect source, int destX, int destY)
To facilitate the call, write an extension protocol as follows:
Public static IEnumerator CutSpriteFromScreen (this RectTransform boxMin, RectTransform boxMax, UnityAction complete) {var sp = new Vector2 (boxMin.position.x, boxMin.position.y); var temp = new Vector2 (boxMax.position.x, boxMax.position.y); Vector2Int size = new Vector2Int ((int) (temp.x-sp.x), (int) (temp.y-sp.y))
/ / determine whether the screenshot box exceeds the screen boundary if (sp.x)
< 0 || sp.y < 0 || sp.x + size.x >Screen.width | | sp.y + size.y > Screen.height) yield break
/ / wait for the rendering of the current frame to finish. This is required yield return new WaitForEndOfFrame ()
Texture2D texture = new Texture2D (size.x, size.y, TextureFormat.RGB24, false)
Texture.ReadPixels (new Rect (sp.x, sp.y, size.x, size.y), 0,0, false); texture.Apply ()
Complete (Sprite.Create (texture, new Rect (Vector2Int.zero, size), Vector2.one * .5F);}
The call is as follows:
StartCoroutine (BoxMin.CutSpriteFromScreen (BoxMax, (x) = > GameData.Instance.PlayerData.Bag.FragCutIcon = x))
Effect display:
The assembled chip image can be directly intercepted and saved to show the installation effect in other interfaces, eliminating the need to grid each interface and re-read the data and calculate it again.
Because in fact, each chip needs to be operated in detail only on the page where the chip is set, and other locations can be reduced to showing a thumbnail.
When the installation of the chip changes, update the thumbnail synchronously.
The above is all the contents of the article "how Unity takes screenshots to create Sprite in any area". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.