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.backgroundMeshData0.textureData.Length != imageByteSize) { this.backgroundMeshData0.textureData = new byte[imageByteSize]; } // Copy the image into a byte array if (image.CopyToBuffer(this.backgroundMeshData0.textureData)) { // Generate a texture from the byte array if (!this.backgroundMeshData0.texture || this.backgroundMeshData0.texture.width != imageWidth || this.backgroundMeshData0.texture.height != imageHeight) { this.backgroundMeshData0.texture = CreateTexture( imageWidth, imageHeight, image.GetFormat()); this.backgroundMeshData0.material.mainTexture = this.backgroundMeshData0.texture; this.UpdateBackgroundSize(); } if (this.backgroundMeshData0.texture) { this.backgroundMeshData0.texture.LoadRawTextureData( this.backgroundMeshData0.textureData); this.backgroundMeshData0.texture.Apply(); } } } else { Debug.LogWarning("[vlUnitySDK] Image size is 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(); } } } }