Beispiel #1
0
    private static Texture2D CreateTexture(int width, int height,
                                           VLUnitySdk.ImageFormat imageFormat)
    {
        switch (imageFormat)
        {
        case VLUnitySdk.ImageFormat.Grey:
            return(new Texture2D(width, height, TextureFormat.Alpha8, false));

        case VLUnitySdk.ImageFormat.RGB:
            return(new Texture2D(width, height, TextureFormat.RGB24, false));

        case VLUnitySdk.ImageFormat.RGBA:
            return(new Texture2D(width, height, TextureFormat.RGBA32, false));
        }

        return(null);
    }
Beispiel #2
0
    private static TextureFormat ImageFormatToTextureFormat(
        VLUnitySdk.ImageFormat imageFormat)
    {
        switch (imageFormat)
        {
        case VLUnitySdk.ImageFormat.Grey:
            return(TextureFormat.Alpha8);

        case VLUnitySdk.ImageFormat.RGB:
            return(TextureFormat.RGB24);

        case VLUnitySdk.ImageFormat.RGBA:
            return(TextureFormat.RGBA32);
        }

        throw new ArgumentException("Unsupported image format");
    }
Beispiel #3
0
    private void OnImage(VLImageWrapper image)
    {
        // Use camera image as texture
        int imageWidth  = image.GetWidth();
        int imageHeight = image.GetHeight();

        if (imageWidth > 0 && imageHeight > 0)
        {
            int imageByteSize = imageWidth * imageHeight *
                                image.GetBytesPerPixel();
            if (this.textureData == null ||
                this.textureData.Length != imageByteSize)
            {
                this.textureData = new byte[imageByteSize];
            }

            // Copy the image into a byte array
            if (image.CopyToBuffer(this.textureData))
            {
                // Generate a texture from the byte array
                VLUnitySdk.ImageFormat imageFormat   = image.GetFormat();
                TextureFormat          textureFormat =
                    ImageFormatToTextureFormat(imageFormat);
                if (!this.texture ||
                    this.texture.width != imageWidth ||
                    this.texture.height != imageHeight ||
                    this.texture.format != textureFormat)
                {
                    this.texture = new Texture2D(
                        imageWidth, imageHeight, textureFormat, false);
                    this.rawImage.texture = this.texture;

                    this.UpdateImageSize();
                }

                if (this.texture)
                {
                    this.texture.LoadRawTextureData(this.textureData);
                    this.texture.Apply();
                }
            }
        }
    }