示例#1
0
        /// <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();
            }
        }
示例#2
0
        /// <summary>
        ///		Initilizes a new image with mutliple frame cells spaced evenly out from a file.
        /// </summary>
        /// <param name="path">Memory location (or url) of image file to load.</param>
        /// <param name="cellW">Width of each cell in image.</param>
        /// <param name="cellH">Height of each cell in image.</param>
        /// <param name="cellHSeperation">Vertical seperation of each cell in image.</param>
        /// <param name="cellVSeperation">Horizontal seperation of each cell in image.</param>
        public Image(object path, int cellW, int cellH, int cellHSeperation, int cellVSeperation, 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;
            }

            _width    = cellW;
            _height   = cellH;
            _hSpacing = cellHSeperation;
            _vSpacing = cellVSeperation;
            _flags    = flags;

            CreateFrames();

            // 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;
                for (int i = 0; i < _frames.Length; i++)
                {
                    _frames[i].PixelMap.Data = null;
                }
                //GC.Collect();
            }
        }
示例#3
0
 /// <summary>
 ///		Saves the given image to an image file.
 /// </summary>
 /// <param name="url">Location to save the image to.</param>
 /// <param name="image">Image to save to file.</param>
 /// <param name="flags">Bitmask of flags describing how to save the image/</param>
 /// <param name="frame">Index of frame to save.</param>
 /// <returns></returns>
 public static bool SaveImage(object url, Image image, PixelMapSaveFlags flags, int frame)
 {
     return(PixelMapFactory.SavePixelMap(url, image[frame].PixelMap, flags));
 }