private dynamic CompressedImageToPsiImage(RosMessage message)
        {
            // get format
            var format = (string)message.GetField("format");

            var imageMemoryStream = new MemoryStream(message.GetField("data"));

            using (var image = System.Drawing.Image.FromStream(imageMemoryStream))
            {
                var bitmap = new System.Drawing.Bitmap(image);
                using (var sharedImage = ImagePool.GetOrCreate(image.Width, image.Height, PixelFormat.BGR_24bpp))
                {
                    sharedImage.Resource.CopyFrom(bitmap);
                    return(sharedImage.AddRef());
                }
            }
        }
Пример #2
0
        private dynamic RosMessageToPsiImage(RosMessage message)
        {
            int width  = (int)message.GetField("width");
            int height = (int)message.GetField("height");

            // convert formats
            string encoding = (string)message.GetField("encoding");
            var    format   = EncodingToPixelFormat(encoding);

            if (format == PixelFormat.Undefined)
            {
                Console.WriteLine($"Image Encoding Type {encoding} is not supported. Defaulting to writeout");
                return(false);
                // throw new NotSupportedException($"Image Encoding Type {encoding} is not supported");
            }

            using (var sharedImage = ImagePool.GetOrCreate(width, height, PixelFormat.BGRA_32bpp))
            {
                sharedImage.Resource.CopyFrom(message.GetRawField("data"));
                return(sharedImage);
            }
        }
        private dynamic ImageToPsiImage(RosMessage message)
        {
            int width  = (int)message.GetField("width");
            int height = (int)message.GetField("height");

            // convert formats
            string encoding = (string)message.GetField("encoding");
            var    format   = this.EncodingToPixelFormat(encoding);

            if (format == PixelFormat.Undefined)
            {
                Console.WriteLine($"Image Encoding Type {encoding} is not supported. Defaulting to writeout");
                throw new NotSupportedException($"Image Encoding Type {encoding} is not supported");
            }

            using (var sharedImage = ImagePool.GetOrCreate(width, height, format))
            {
                // skip the first 4 bytes because in ROS Message its a varied length array where the first 4 bytes tell us the length.
                sharedImage.Resource.CopyFrom(message.GetField("data"));
                return(sharedImage.AddRef());
                // return sharedImage;
            }
        }