示例#1
0
        private DXImage GetImageForImageElement(ImageElement element)
        {
            DXImage result = null;

            if (!_imageCache.TryGetValue(element, out result))
            {
                result = ToDispose(new DXImage(_device, _deviceContext));
                result.Initialise(element.Bitmap);
                _imageCache[element] = result;
            }

            return result;
        }
示例#2
0
        private Texture GetImageForImageElement(ImageElement element)
        {
            Texture result = null;

            if (!string.IsNullOrEmpty(element.Filename))
            {
                if (!_imageCache.TryGetValue(element, out result))
                {
                    result = ToDispose(Texture.FromFile(Device, element.Filename));

                    _imageCache[element] = result;
                }
            }
            else
            {
                if (!_imageCache.TryGetValue(element, out result) && element.Bitmap != null)
                {
                    using (var ms = new MemoryStream())
                    {
                        // TODO: hard-coded target format problematic?
                        element.Bitmap.Save(ms, ImageFormat.Png);
                        ms.Seek(0, SeekOrigin.Begin);
                        result = ToDispose(Texture.FromStream(Device, ms));
                    }

                    _imageCache[element] = result;
                }
            }

            return result;
        }