/// <summary> /// Initilizes a new image from a file. /// </summary> /// <param name="path">Memory location (or url) of image file to load.</param> public Image(object path, ImageFlags flags) { if ((path is PixelMap) == false) { if (path is string) { _url = (string)path; } _fullPixelMap = PixelMapFactory.LoadPixelMap(path); } else { _fullPixelMap = (path as PixelMap).Copy(); } if (_fullPixelMap == null) { return; } PixelMap map = _fullPixelMap.Copy(); map.Mask(GraphicsManager.ColorKey); _mask = GraphicsManager.ColorKey; _width = _fullPixelMap.Width; _height = _fullPixelMap.Height; _flags = flags; _frames[0] = GraphicsManager.CreateImageFrame(map); // Are we dynamic? If not we don't need the full pixelmaps data so lets destroy it and // free up a bit of memory. if ((_flags & ImageFlags.Dynamic) == 0 && _fullPixelMap != null) { _fullPixelMap.Data = null; _frames[0].PixelMap.Data = null; //GC.Collect(); } }
/// <summary> /// Recreates the pixel maps and resources required to render this image. /// </summary> public void CreateFrames() { if (_frames == null) { return; } if (_fullPixelMap != null) { if (_width > _fullPixelMap.Width) { _width = _fullPixelMap.Width; } if (_height > _fullPixelMap.Height) { _height = _fullPixelMap.Height; } int cellsH = (_fullPixelMap.Width / (_width + _hSpacing)); int cellsV = (_fullPixelMap.Height / (_height + _vSpacing)); _frames = new IImageFrame[cellsH * cellsV]; for (int i = 0; i < _frames.Length; i++) { int px = (i % cellsH) * _width; int py = (i / cellsH) * _height; PixelMap map = _fullPixelMap.Copy(px + ((i % cellsH) * _hSpacing), py + ((i / cellsH) * _vSpacing), _width, _height); map.Mask(GraphicsManager.ColorKey); _frames[i] = GraphicsManager.CreateImageFrame(map); } } else { for (int i = 0; i < _frames.Length; i++) { _frames[i] = GraphicsManager.CreateImageFrame(new PixelMap(_width, _height)); } } _mask = GraphicsManager.ColorKey; }