示例#1
0
        public static RotateFlipType GetFlipTypeRotatedCW(RotateFlipType currentRotation)
        {
            RotateFlipType newRotation;

            switch (currentRotation)
            {
            case RotateFlipType.RotateNoneFlipNone:
                newRotation = RotateFlipType.Rotate90FlipNone;
                break;

            case RotateFlipType.Rotate90FlipNone:
                newRotation = RotateFlipType.Rotate180FlipNone;
                break;

            case RotateFlipType.Rotate180FlipNone:
            case RotateFlipType.RotateNoneFlipY:     // legacy images
                newRotation = RotateFlipType.Rotate270FlipNone;
                break;

            case RotateFlipType.Rotate270FlipNone:
                newRotation = RotateFlipType.RotateNoneFlipNone;
                break;

            default:
                Debug.Fail("Unknown RotateFlipType encountered: " + currentRotation.ToString());
                newRotation = RotateFlipType.RotateNoneFlipNone;
                break;
            }
            return(newRotation);
        }
 public static RotateFlipType GetFlipTypeRotatedCW(RotateFlipType currentRotation)
 {
     RotateFlipType newRotation;
     switch (currentRotation)
     {
         case RotateFlipType.RotateNoneFlipNone:
             newRotation = RotateFlipType.Rotate90FlipNone;
             break;
         case RotateFlipType.Rotate90FlipNone:
             newRotation = RotateFlipType.Rotate180FlipNone;
             break;
         case RotateFlipType.Rotate180FlipNone:
         case RotateFlipType.RotateNoneFlipY: // legacy images
             newRotation = RotateFlipType.Rotate270FlipNone;
             break;
         case RotateFlipType.Rotate270FlipNone:
             newRotation = RotateFlipType.RotateNoneFlipNone;
             break;
         default:
             Debug.Fail("Unknown RotateFlipType encountered: " + currentRotation.ToString());
             newRotation = RotateFlipType.RotateNoneFlipNone;
             break;
     }
     return newRotation;
 }
        private static void TestHalfArea(string testObject, Bitmap bitmap, RotateFlipType rft, int scale)
        {
            int xSize = Math.Max(bitmap.Width, bitmap.Height) * scale;
            int ySize = xSize;

            OutlineShape actual = SWA_Ariadne_Outlines_TilesOutlineShapeAccessor.FromBitmap(xSize, ySize, bitmap, rft, scale);

            Assert.AreEqual(xSize * ySize / 2, actual.Area, testObject + " " + rft.ToString() + ": incorrect Area");
        }
示例#4
0
        /// <summary>
        /// Builds a pattern from the given bitmap, rotated and scaled.
        /// </summary>
        /// <param name="xSize"></param>
        /// <param name="ySize"></param>
        /// <param name="bitmap"></param>
        /// <param name="rft"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        private static OutlineShape FromBitmap(int xSize, int ySize, Bitmap bitmap, RotateFlipType rft, int scale)
        {
#if false
            System.Console.Out.WriteLine("[TilesOutlineShape.FromBitmap] " + rft.ToString() + ", x" + scale.ToString());
#endif

#if false
            // Note: Some bitmaps are useless (all black or all white) after the RotateFlip() operation!
            Bitmap template = (Bitmap)bitmap.Clone();
            template.RotateFlip(rft);
            TilesOutlineShape result = new TilesOutlineShape(xSize, ySize, template);
#else
            OutlineShape      tile   = new ExplicitOutlineShape(bitmap).RotatedOrFlipped(rft);
            TilesOutlineShape result = new TilesOutlineShape(xSize, ySize, tile as ExplicitOutlineShape);
#endif
            result.SetRepetitions(scale);

            return(result);
        }
示例#5
0
 public static RotateFlipType CombineFlipAndRotate(RotateFlipType flip, double angle)
 {
     if (flip != (RotateFlipType)FlipMode.None &&
         flip != (RotateFlipType)FlipMode.X &&
         flip != (RotateFlipType)FlipMode.Y &&
         flip != (RotateFlipType)FlipMode.XY)
     {
         throw new ArgumentException("Valid flip values are RotateNoneFlipNone, RotateNoneFlipX, RotateNoneFlipY, and RotateNoneFlipXY. Rotation must be specified with Rotate or srcRotate instead. Received: " + flip.ToString());
     }
     return(CombineFlipAndRotate((FlipMode)flip, angle));
 }
示例#6
0
文件: test.cs 项目: wateras/winforms
    static void Main()
    {
        foreach (string type_name in Enum.GetNames(typeof(RotateFlipType)))
        {
            RotateFlipType type = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), type_name);

            if (type_name != type.ToString())
            {
                Console.WriteLine("- processing {0} ({1})...", type_name, type);
            }
            else
            {
                Console.WriteLine("- processing {0}...", type_name);
            }

            Bitmap result = null;

            try
            {
                result = load("24bit.png");
                result.RotateFlip(type);
            }
            catch (Exception e)
            {
                Console.WriteLine("EXCEPTION (24-bit): {0}: {1}", e.GetType().Name, e.Message);
                if (result != null)
                {
                    try { result.Dispose(); } catch {}
                }
                result = null;
            }

            if (result != null)
            {
                result.Save("24bit_" + type_name + ".png", ImageFormat.Png);
            }

            try { result.Dispose(); } catch {}

            try
            {
                Bitmap intermediate = load("24bit.png");
                result = new Bitmap(intermediate.Width, intermediate.Height, PixelFormat.Format16bppRgb565);
                using (Graphics g = Graphics.FromImage(result))
                {
                    Rectangle bounds = new Rectangle(0, 0, result.Width, result.Height);
                    g.DrawImage(intermediate, bounds, bounds, GraphicsUnit.Pixel);
                }

                result.RotateFlip(type);
            }
            catch (Exception e)
            {
                Console.WriteLine("EXCEPTION (16-bit): {0}: {1}", e.GetType().Name, e.Message);
                if (result != null)
                {
                    try { result.Dispose(); } catch {}
                }
                result = null;
            }

            if (result != null)
            {
                result.Save("16bit_" + type_name + ".png", ImageFormat.Png);
            }

            try { result.Dispose(); } catch {}

            try
            {
                result = load("8bit.png");
                result.RotateFlip(type);
            }
            catch (Exception e)
            {
                Console.WriteLine("EXCEPTION (8-bit): {0}: {1}", e.GetType().Name, e.Message);
                if (result != null)
                {
                    try { result.Dispose(); } catch {}
                }
                result = null;
            }

            if (result != null)
            {
                result.Save("8bit_" + type_name + ".png", ImageFormat.Png);
            }

            try { result.Dispose(); } catch {}
        }

        Console.WriteLine("done!");
    }
示例#7
0
 public static RotateFlipType CombineFlipAndRotate(RotateFlipType flip, double angle)
 {
     if (flip != (RotateFlipType)FlipMode.None &&
         flip != (RotateFlipType)FlipMode.X &&
         flip != (RotateFlipType)FlipMode.Y &&
         flip != (RotateFlipType)FlipMode.XY)
         throw new ArgumentException("Valid flip values are RotateNoneFlipNone, RotateNoneFlipX, RotateNoneFlipY, and RotateNoneFlipXY. Rotation must be specified with Rotate or srcRotate instead. Received: " + flip.ToString());
     return CombineFlipAndRotate((FlipMode)flip, angle);
 }
示例#8
0
 public override string GetShortDescription()
 {
     return(RotateFlipType.ToString());
 }
示例#9
0
文件: Utils.cs 项目: timgaunt/resizer
        /// <summary>
        /// Throws an exception if the specified value is unsupported. Rotation values are not supported, and should be specified with the Rotate or srcRotate command.
        /// </summary>
        /// <returns></returns>
        public static string writeFlip(RotateFlipType flip)
        {
            if (flip == RotateFlipType.RotateNoneFlipNone)
            {
                return("none");
            }
            if (flip == RotateFlipType.RotateNoneFlipX)
            {
                return("x");
            }
            if (flip == RotateFlipType.RotateNoneFlipY)
            {
                return("y");
            }
            if (flip == RotateFlipType.RotateNoneFlipXY)
            {
                return("xy");
            }

            throw new ArgumentException("Valid flip values are RotateNoneFlipNone, RotateNoneFlipX, RotateNoneFlipY, and RotateNoneFlipXY. Rotation must be specified with Rotate or srcRotate instead. Received: " + flip.ToString());
        }
示例#10
0
    static void Main()
    {
        foreach (string type_name in Enum.GetNames(typeof(RotateFlipType)))
        {
            RotateFlipType type = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), type_name);

            if (type_name != type.ToString())
            {
                Console.WriteLine("- processing {0} ({1})...", type_name, type);
            }
            else
            {
                Console.WriteLine("- processing {0}...", type_name);
            }

            Bitmap result = null;

            try
            {
                result = load("1bit.png");
                result.RotateFlip(type);
            }
            catch (Exception e)
            {
                Console.WriteLine("EXCEPTION: {0}: {1}", e.GetType().Name, e.Message);
                if (result != null)
                {
                    try { result.Dispose(); } catch {}
                }
                result = null;
            }

            if (result != null)
            {
                result.Save("1bit_" + type_name + ".png", ImageFormat.Png);
            }

            try { result.Dispose(); } catch {}

            try
            {
                result = load("4bit.png");
                result.RotateFlip(type);
            }
            catch (Exception e)
            {
                Console.WriteLine("EXCEPTION: {0}: {1}", e.GetType().Name, e.Message);
                if (result != null)
                {
                    try { result.Dispose(); } catch {}
                }
                result = null;
            }

            if (result != null)
            {
                result.Save("4bit_" + type_name + ".png", ImageFormat.Png);
            }

            try { result.Dispose(); } catch {}
        }

        Console.WriteLine("done!");
    }