Exemplo n.º 1
0
        public void IsRegionBlank()
        {
            var region = new Rectangle(5, 5, 5, 5);

            Assert.IsFalse(src.IsRegionBlank(region, 0.05));

            for (int j = region.Top; j < region.Bottom; j++)
            {
                for (int i = region.Left; i < region.Right; i++)
                {
                    var clr = src.GetPixel(i, j);

                    src.SetPixel(i, j, Color.FromArgb(0, clr.R, clr.G, clr.B));
                }
            }

            Assert.IsTrue(src.IsRegionBlank(region, 0.05));
            Assert.IsFalse(src.IsBlank(0.05));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Slices and dices the image passed into frames and adds them.
        /// Frames are taken from the surface from left to right.
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="ownSurface">Pass true to indicate that this sprite should own the surface, and handle its disposal.</param>
        /// <param name="startPoint">The starting point in pixels from which to parse frames.</param>
        /// <param name="size">The size of the image to cut out for each frame</param>
        /// <param name="extraSpace">How many extra pixels to insert between each frame.</param>
        /// <param name="skipBlank">Whether or not blank frames should be automatically dropped.</param>
        public void AddNewFrames(Surface surface, bool ownSurface, Point startPoint, Point extraSpace, Size size, bool skipBlank)
        {
            Point       location = startPoint;
            PixelBuffer pixels   = surface.ReadPixels();

            if (ownSurface)
            {
                mOwnedSurfaces.Add(surface);
            }

            do
            {
                SpriteFrame currentFrame = new SpriteFrame(surface);
                Rectangle   currentRect  = new Rectangle(location, size);
                bool        skip         = false;

                currentFrame.SourceRect = currentRect;
                currentFrame.SpriteSize = SpriteSize;

                if (currentFrame.SourceRect.Right > pixels.Width)
                {
                    skip = true;
                }
                if (currentFrame.SourceRect.Bottom > pixels.Height)
                {
                    skip = true;
                }

                if (skipBlank && pixels.IsRegionBlank(currentFrame.SourceRect))
                {
                    skip = true;
                }

                if (skip == false)
                {
                    mFrames.Add(currentFrame);
                }

                location.X += size.Width;

                if (location.X + size.Width > surface.SurfaceWidth)
                {
                    location.X  = 0;
                    location.Y += size.Height;
                }
            } while (location.Y + size.Height < surface.SurfaceHeight);
        }