When we save the picture to the server
Doesn't just keep the original.
A thumbnail image is usually saved separately
Load thumbnails only when folders are loaded
When you click the thumbnail to open the picture
Reload the original thumbnail image
To save time and memory
The following is an example of saving a screen to a server
Save the screen and thumbnails to the server
Private IEnumerator uploadpng (string id) {yield return new waitforendofframe (); int width = screen.width; int height = screen.height; Screen texture2d tex = new texture2d (width, height, textureformat.argb32, false); Tex. Readpixels (New Rect (0, 0, width, height), 0, 0); Tex. Apply (); byte[] bytes = Tex. Encodetopng (); Thumbnail (256*256) texture2d texthumb = new Texture2d (256, 256); Compress picture color[] Destpix = new color[texthumb.width * Texthumb.height]; float warpfactor = 1.0f; int y = 0; while (Y < texthumb.height) {int x = 0; while (x < texthumb.width) {float Xfrac = x * 1.0F/(TEXTHUMB.WIDTH-1); float Yfrac = y * 1.0F/(TEXTHUMB.HEIGHT-1); float Warpxfrac = Mathf.pow (Xfrac, warpfactor); float Warpyfrac = Mathf.pow (Yfrac, warpfactor); Color C0 = Tex. GEtpixelbilinear (Warpxfrac, Warpyfrac); Xfrac = (x-1) * 1.0F/(TEXTHUMB.WIDTH-1); Yfrac = y * 1.0F/(TEXTHUMB.HEIGHT-1); Warpxfrac = Mathf.pow (Xfrac, warpfactor); Warpyfrac = Mathf.pow (Yfrac, warpfactor); Color C1 = Tex. Getpixelbilinear (Warpxfrac, Warpyfrac); Xfrac = (x + 1) * 1.0F/(TEXTHUMB.WIDTH-1); Yfrac = y * 1.0F/(TEXTHUMB.HEIGHT-1); Warpxfrac = Mathf.pow (Xfrac, warpfactor); Warpyfrac = Mathf.pow (Yfrac, warpfactor); Color C2 = Tex. Getpixelbilinear (Warpxfrac, Warpyfrac); Xfrac = (x + 1) * 1.0F/(TEXTHUMB.WIDTH-1); Yfrac = (y-1) * 1.0F/(TEXTHUMB.HEIGHT-1); Warpxfrac = Mathf.pow (Xfrac, warpfactor); Warpyfrac = Mathf.pow (Yfrac, warpfactor); Color C3 = Tex. Getpixelbilinear (Warpxfrac, Warpyfrac); Xfrac = (x-0) * 1.0F/(texthUMB.WIDTH-1); Yfrac = (y-1) * 1.0F/(TEXTHUMB.HEIGHT-1); Warpxfrac = Mathf.pow (Xfrac, warpfactor); Warpyfrac = Mathf.pow (Yfrac, warpfactor); Color C4 = Tex. Getpixelbilinear (Warpxfrac, Warpyfrac); Xfrac = (x-1) * 1.0F/(TEXTHUMB.WIDTH-1); Yfrac = (y-1) * 1.0F/(TEXTHUMB.HEIGHT-1); Warpxfrac = Mathf.pow (Xfrac, warpfactor); Warpyfrac = Mathf.pow (Yfrac, warpfactor); Color C5 = Tex. Getpixelbilinear (Warpxfrac, Warpyfrac); Xfrac = (x + 1) * 1.0F/(TEXTHUMB.WIDTH-1); Yfrac = (y + 1) * 1.0F/(TEXTHUMB.HEIGHT-1); Warpxfrac = Mathf.pow (Xfrac, warpfactor); Warpyfrac = Mathf.pow (Yfrac, warpfactor); Color C6 = Tex. Getpixelbilinear (Warpxfrac, Warpyfrac); Xfrac = (x-0) * 1.0F/(TEXTHUMB.WIDTH-1); Yfrac = (y + 1) * 1.0F/(texthumb.height-1); Warpxfrac = Mathf.pow (Xfrac, warpfactor); Warpyfrac = Mathf.pow (Yfrac, warpfactor); Color c7 = Tex. Getpixelbilinear (Warpxfrac, Warpyfrac); Xfrac = (x-1) * 1.0F/(TEXTHUMB.WIDTH-1); Yfrac = (y + 1) * 1.0F/(TEXTHUMB.HEIGHT-1); Warpxfrac = Mathf.pow (Xfrac, warpfactor); Warpyfrac = Mathf.pow (Yfrac, warpfactor); Color C8 = Tex. Getpixelbilinear (Warpxfrac, Warpyfrac); Color cr = C0 * 0.25f + C1 * 0.125f + c2 * 0.125f + c3 * 0.0625f + c4 * 0.125f + c5 * 0.0625f + c6 * 0.0625f + c7 * 0.125f + C8 * 0.0625F; Destpix[y * texthumb.width + x] = CR; x + +; } y++; } texthumb.setpixels (Destpix); Texthumb.apply (); byte[] Bytesthumb = Texthumb.encodetopng ();
Destroy (Tex); Destroy (TEXTHUMB);
Wwwform upload to server wwwform form = new Wwwform (); Form. AddField ("cmd", "Savedraw"); Form. Addbinarydata ("screenshot", Bytesthumb); Form. Addbinarydata ("Draw", bytes); www w = new www (url, form); Yield return w; if (w.error! = null) {Debug.Log ("error:" + w.error); } else Debug.Log ("OK"); }
Unity Compression Texture