Ejemplo n.º 1
0
    IEnumerator CaptureScreenshot(int _item)
    {
        screenshotTaken = false;

        yield return(new WaitForEndOfFrame());

        string path = imageFolder + _item + ".jpg";

        Texture2D img = new Texture2D(Screen.width, Screen.height);

        // reads the screen pixels and applies to texture
        img.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
        img.Apply();

        if (_item == (int)(VideoRecord.mostRecentRecording.Length * 300) / captureTimeMax / 2)
        {
            Color col = sampler.saveNewColor(img);
            Debug.Log("Color saved at Item: " + _item + " was: " + col);
            int    r   = (int)(col.r * 255);
            int    g   = (int)(col.g * 255);
            int    b   = (int)(col.b * 255);
            string hex = r.ToString("X2") + g.ToString("X2") + b.ToString("X2");
            Debug.Log("That's Hex String: " + hex);
            sampler.newestColorHex = hex;
        }
        // converts texture to JPG and writes to folder path
        byte[] bytes = img.EncodeToJPG();
        System.IO.File.WriteAllBytes(path, bytes);

        Destroy(img);

        if (debugActive)
        {
            Debug.Log("Screenshot " + _item + ".jpg has been saved!");
        }
    }