コード例 #1
0
    public static Texture2D captureFrame()
    {
        const int DOWN_SAMPLE_RATE = 1;
        int       FRAME_WIDTH      = 2048;

        Texture2D  frame;
        IPcLink    link    = HPPC.CreateLink();
        IPcMoment  moment  = link.CaptureMoment();
        IPcPicture picture = link.ExtractPicture(moment);
        Bitmap     bmp     = SproutExtension.createBitmap(picture.Image);

        GraphicsUnit units = GraphicsUnit.Pixel;
        RectangleF   rect = bmp.GetBounds(ref units);
        int          width = (int)rect.Width / DOWN_SAMPLE_RATE, height = (int)rect.Height / DOWN_SAMPLE_RATE;

        frame = new Texture2D(FRAME_WIDTH, FRAME_WIDTH);

        int xOffset = (width / 2) - (FRAME_WIDTH / 2);
        int yOffset = (height / 2) - (FRAME_WIDTH / 2);

        UnityEngine.Color[] colors = new UnityEngine.Color[FRAME_WIDTH * FRAME_WIDTH];

        for (int x = 0; x < FRAME_WIDTH; x++)
        {
            for (int y = 0; y < FRAME_WIDTH; y++)
            {
                System.Drawing.Color sysColor = bmp.GetPixel(xOffset + x, yOffset + y);
                Color32 uc32 = new Color32(sysColor.R, sysColor.B, sysColor.G, sysColor.A);
                //UnityEngine.Color unityColor = new UnityEngine.Color((float)sysColor.R / 255f, (float)sysColor.G / 255f, (float)sysColor.B / 255f, (float)sysColor.A / 255f);
                int index = (FRAME_WIDTH - 1 - y) * FRAME_WIDTH + x;
                if (index < colors.Length && index >= 0)
                {
                    colors[index] = uc32;
                }
                else
                {
                    Debug.Log("Index out of range.");
                }
            }
        }

        // test - only take a square of pixels in middle of screen

        frame.SetPixels(colors);

        frame.Apply();

        TextureScale.Point(frame, 1024, 1024);

        return(frame);
    }
コード例 #2
0
    private IEnumerator getFrameFromSprout(bool goBackToAnimEditScreen = false)
    {
        yield return(new WaitForSeconds(0.5f));

        Texture2D texture;

        if (usingSprout)
        {
            texture = SproutExtension.captureFrame();
        }
        else
        {
            texture = testTexture;
        }
        setLoadingState(false);
        frameEditScreen.setCurrentFrame(texture, !goBackToAnimEditScreen);
        if (goBackToAnimEditScreen)
        {
            frameEditScreen.done();
        }
        yield return(null);
    }