Ejemplo n.º 1
0
        public void cmd_StretchChanged(object sender, RoutedEventArgs e)
        {
            if (this.rdb_Fill.IsChecked == true)
            {
                this.stretchMode     = StretchMode.FILL;
                this.Overlay.Stretch = Stretch.Fill;
                return;
            }

            if (this.rdb_Uniform.IsChecked == true)
            {
                this.stretchMode     = StretchMode.UNIFORM;
                this.Overlay.Stretch = Stretch.Uniform;
                return;
            }

            if (this.rdb_None.IsChecked == true)
            {
                this.stretchMode     = StretchMode.NONE;
                this.Overlay.Stretch = Stretch.None;
                return;
            }

            if (this.rdb_UniformFill.IsChecked == true)
            {
                this.stretchMode     = StretchMode.UNIFORM_FILL;
                this.Overlay.Stretch = Stretch.UniformToFill;
            }
        }
Ejemplo n.º 2
0
            public static bool SetBackground(string path, StretchMode stretchMode = StretchMode.Centered)
            {
                try
                {
                    var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
                    switch (stretchMode)
                    {
                    case StretchMode.Centered:
                        key.SetValue(@"WallpaperStyle", "1");
                        key.SetValue(@"TileWallpaper", "0");
                        break;

                    case StretchMode.Stretched:
                        key.SetValue(@"WallpaperStyle", "2");
                        key.SetValue(@"TileWallpaper", "0");
                        break;

                    case StretchMode.Tiled:
                        key.SetValue(@"WallpaperStyle", "1");
                        key.SetValue(@"TileWallpaper", "1");
                        break;
                    }
                    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
                }
                catch
                {
                    return(false);
                }
                return(true);
            }
        public DistanceTool(StretchMode stretch, IScreenServiceHost host) : base(host)
        {
            this.StretchMode = stretch;

            this.screenshot = this.Host.CurrentScreen;

            this.InitializeComponent();

            if (this.StretchMode == StretchMode.EastWest)
            {
                this.N.Visibility = Visibility.Collapsed;
                this.S.Visibility = Visibility.Collapsed;
            }
            else if (this.StretchMode == StretchMode.NorthSouth)
            {
                this.E.Visibility = Visibility.Collapsed;
                this.W.Visibility = Visibility.Collapsed;
            }
#if !DEBUG
			this.Cursor = Cursors.None;
#endif

            this.Dimensions.CloseClicked += delegate
            {
                this.CloseService();
            };

            this.Loaded += delegate
            {
                this.Update();
            };
        }
Ejemplo n.º 4
0
        public static Image Resize(this Image source, int width, int height, StretchMode mode = StretchMode.Fill, IImageSampler sampler = null)
        {
            if (mode != StretchMode.Fill)
            {
                throw new NotImplementedException();
            }

            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(width));
            }
            if (height <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(height));
            }

            if (width > Image.MaxWidth || width > Image.MaxHeight)
            {
                throw new ArgumentOutOfRangeException(
                          $"Target size '{ width }x{ width }' is bigger then the max allowed size '{ Image.MaxWidth }x{ Image.MaxHeight }'");
            }

            sampler = sampler ?? defaultSampler;
            return(PerformAction(source, image => sampler.Sample(image, width, height)));
        }
Ejemplo n.º 5
0
        public DistanceTool(StretchMode stretch, IScreenServiceHost host) : base(host)
        {
            StretchMode = stretch;

            screenshot = Host.CurrentScreen;

            InitializeComponent();

            if (StretchMode == StretchMode.EastWest)
            {
                N.Visibility = Visibility.Collapsed;
                S.Visibility = Visibility.Collapsed;
            }
            else if (StretchMode == StretchMode.NorthSouth)
            {
                E.Visibility = Visibility.Collapsed;
                W.Visibility = Visibility.Collapsed;
            }
#if !DEBUG
            this.Cursor = Cursors.None;
#endif

            Dimensions.CloseClicked += delegate
            {
                CloseService();
                OnDimensionsCloseClicked(new EventArgs());
            };

            Loaded += delegate
            {
                Update();
            };
        }
Ejemplo n.º 6
0
 public static string writeStretch(StretchMode value)
 {
     if (value == StretchMode.Proportionally)
     {
         return("proportionally");
     }
     else if (value == StretchMode.Fill)
     {
         return("fill");
     }
     throw new NotImplementedException("Unrecognized ScaleMode value: " + value.ToString());
 }
Ejemplo n.º 7
0
        public StretchPattern(StretchMode mode, bool alwaysTop, bool excess)
        {
            //if (mode == StretchMode.Manual)
            //{
            //    if (manualWidth <= 0) throw new ArgumentOutOfRangeException(nameof(manualWidth));
            //    if (manualHeight <= 0) throw new ArgumentOutOfRangeException(nameof(manualHeight));
            //}

            Mode         = mode;
            AlwaysTop    = alwaysTop;
            Excess       = excess;
            ManualWidth  = 0;
            ManualHeight = 0;
        }
Ejemplo n.º 8
0
        public static Image Resize(this Image source, int width, int height, StretchMode mode = StretchMode.Fill, IImageSampler sampler = null)
        {
            if (mode != StretchMode.Fill) throw new NotImplementedException();

            if (width <= 0) throw new ArgumentOutOfRangeException(nameof(width));
            if (height <= 0) throw new ArgumentOutOfRangeException(nameof(height));

            if (width > Image.MaxWidth || width > Image.MaxHeight)
            {
                throw new ArgumentOutOfRangeException(
                    $"Target size '{ width }x{ width }' is bigger then the max allowed size '{ Image.MaxWidth }x{ Image.MaxHeight }'");
            }

            sampler = sampler ?? defaultSampler;
            return PerformAction(source, image => sampler.Sample(image, width, height));
        }
Ejemplo n.º 9
0
        internal static void GetTransform(StretchMode mode, SKRect element, SKRect panel, out double ox, out double oy, out double zx, out double zy)
        {
            ox = element.Left;
            oy = element.Top;
            zx = 1.0;
            zy = 1.0;
            switch (mode)
            {
            default:
            case StretchMode.None:
                break;

            case StretchMode.Center:
                ox = element.Left + (element.Width - panel.Width) / 2;
                oy = element.Top + (element.Height - panel.Height) / 2;
                break;

            case StretchMode.Fill:
                zx = element.Width / panel.Width;
                zy = element.Height / panel.Height;
                ox = element.Left + (element.Width - panel.Width * zx) / 2;
                oy = element.Top + (element.Height - panel.Height * zy) / 2;
                break;

            case StretchMode.Uniform:
                zx = element.Width / panel.Width;
                zy = element.Height / panel.Height;
                zx = Math.Min(zx, zy);
                zy = zx;
                ox = element.Left + (element.Width - panel.Width * zx) / 2;
                oy = element.Top + (element.Height - panel.Height * zy) / 2;
                break;

            case StretchMode.UniformToFill:
                zx = element.Width / panel.Width;
                zy = element.Height / panel.Height;
                zx = Math.Max(zx, zy);
                zy = zx;
                ox = element.Left + (element.Width - panel.Width * zx) / 2;
                oy = element.Top + (element.Height - panel.Height * zy) / 2;
                break;
            }
        }
Ejemplo n.º 10
0
        public static Image Resize(this Image source, int size, StretchMode mode = StretchMode.Fill, IImageSampler sampler = null)
        {
            int width  = 0;
            int height = 0;

            var ratio = source.AspectRatio;

            if (source.Width > source.Height && ratio > 0)
            {
                width  = size;
                height = (int)Math.Round(width / ratio);
            }
            else
            {
                height = size;
                width  = (int)Math.Round(height * ratio);
            }

            return(Resize(source, width, height, mode, sampler));
        }
Ejemplo n.º 11
0
        public static Image Resize(this Image source, int size, StretchMode mode = StretchMode.Fill, IImageSampler sampler = null)
        {
            int width = 0;
            int height = 0;

            var ratio = source.AspectRatio;

            if (source.Width > source.Height && ratio > 0)
            {
                width = size;
                height = (int)Math.Round(width / ratio);
            }
            else
            {
                height = size;
                width = (int)Math.Round(height * ratio);
            }

            return Resize(source, width, height, mode, sampler);
        }
Ejemplo n.º 12
0
        public void resize_image_using_sampler(string filename, int width, int? height, StretchMode mode, IImageSampler sampler)
        {
            var image = Image.Load($"TestImages/{ filename }");
            var watch = Stopwatch.StartNew();

            if (height != null)
            {
                image = image.Resize(width, height.Value, mode, sampler);
            }
            else
            {
                image = image.Resize(width, mode, sampler);
            }

            Trace.WriteLine($"{ sampler.GetType().Name }: { watch.ElapsedMilliseconds}ms");

            height = height ?? width;

            
            var outputFile = $"TestResult/Resized/{ Path.GetFileNameWithoutExtension(filename) }.{ mode }.{ sampler.GetType().Name }.{ width }x{ height }.jpg";
            image.VerifyAndSave(outputFile);
        }
Ejemplo n.º 13
0
        public bool LoadSprite(XElement spriteValues, string graphicDirectory, out string reason)
        {
            string filename = null;

            Name = null;
            foreach (var attribute in spriteValues.Attributes())
            {
                //Get the graphic file
                switch (attribute.Name.ToString().ToLower())
                {
                case "file":
                {
                    filename = attribute.Value;
                    break;
                }

                case "name":
                {
                    Name = attribute.Value;
                    break;
                }

                case "stretchmode":
                {
                    if (attribute.Value == "repeat")
                    {
                        stretchMode = StretchMode.REPEAT;
                    }
                    break;
                }
                }
            }
            if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(filename))
            {
                reason = "No sprite name or file location.";
                return(false);
            }
            Sprite graphicFile;

            if (ImageCache.Images.Contains(Name))
            {
                graphicFile = new Sprite(Name, ImageCache.Images[Name]);
            }
            else
            {
                string path = Path.Combine(graphicDirectory, filename);
                if (!File.Exists(path))
                {
                    reason = "Graphic File doesn't exist: " + path;
                    return(false);
                }
                graphicFile = new Sprite(Name, Image.FromFile(Path.Combine(graphicDirectory, filename)));
            }

            int frameCount = 0;

            foreach (var element in spriteValues.Elements())
            {
                int    x           = 0;
                int    y           = 0;
                int    width       = 0;
                int    height      = 0;
                int    axisX       = 0;
                int    axisY       = 0;
                string frameLength = null;
                //Process each frame
                foreach (var attribute in element.Attributes())
                {
                    switch (attribute.Name.ToString().ToLower())
                    {
                    case "x":
                    {
                        x = int.Parse(attribute.Value);
                        break;
                    }

                    case "y":
                    {
                        y = int.Parse(attribute.Value);
                        break;
                    }

                    case "width":
                    {
                        width = int.Parse(attribute.Value);
                        break;
                    }

                    case "height":
                    {
                        height = int.Parse(attribute.Value);
                        break;
                    }

                    case "framelength":
                    {
                        frameLength = attribute.Value;
                        break;
                    }

                    case "axisx":
                    {
                        axisX = int.Parse(attribute.Value);
                        break;
                    }

                    case "axisy":
                    {
                        axisY = int.Parse(attribute.Value);
                        break;
                    }
                    }
                }
                var frame = new Sprite(Name + frameCount, graphicFile.Image, x, y, width, height, axisX,
                                       axisY);
                if (stretchMode == StretchMode.REPEAT)
                {
                    frame.WrapMode = ImageAddressing.Wrapping;
                }
                Frames.Add(frame);
                FrameLength.Add(frameLength);
                frameCount++;
            }
            reason = null;
            return(true);
        }
Ejemplo n.º 14
0
 public BaseSprite()
 {
     Frames      = new List <Sprite>();
     FrameLength = new List <string>();
     stretchMode = StretchMode.STRETCH;
 }
Ejemplo n.º 15
0
 public static Image Width(this Image source, int width, int height = -1, StretchMode mode = StretchMode.Fill, IImageSampler sampler = null)
     => Resize(source, width, height >= 0 ? height : (int)Math.Round(width / source.AspectRatio), mode, sampler);
Ejemplo n.º 16
0
        public static void Scale(ref double width, ref double height, double maxWidth, double maxHeight, StretchMode mode = StretchMode.Uniform)
        {
            if (mode == StretchMode.None)
            {
                return;
            }

            if (mode == StretchMode.Fill)
            {
                width  = maxWidth;
                height = maxHeight;
                return;
            }

            var    ratioX = (double)maxWidth / width;
            var    ratioY = (double)maxHeight / height;
            double ratio  = 0;

            if (mode == StretchMode.Uniform)
            {
                ratio = Math.Min(ratioX, ratioY);
            }

            if (mode == StretchMode.UniformToFill)
            {
                ratio = Math.Max(ratioX, ratioY);
            }

            width  = (int)(width * ratio);
            height = (int)(height * ratio);
        }
 public static extern bool SetStretchBltMode(IntPtr hdc, StretchMode iStretchMode);
Ejemplo n.º 18
0
 public static Image Height(this Image source, int height, int width = -1, StretchMode mode = StretchMode.Fill, IImageSampler sampler = null)
 => Resize(source, width >= 0 ? width : (int)Math.Round(height * source.AspectRatio), height, mode, sampler);
Ejemplo n.º 19
0
 public BaseSprite()
 {
     Frames = new List<Sprite>();
     FrameLength = new List<string>();
     stretchMode = StretchMode.STRETCH;
 }
Ejemplo n.º 20
0
 public static Image Width(this Image source, int width, int height = -1, StretchMode mode = StretchMode.Fill, IImageSampler sampler = null)
 => Resize(source, width, height >= 0 ? height : (int)Math.Round(width / source.AspectRatio), mode, sampler);
Ejemplo n.º 21
0
 public static extern bool SetStretchBltMode(IntPtr hdc, StretchMode iStretchMode);
Ejemplo n.º 22
0
        /// <summary>
        /// Reads the object's properties from the buffer
        /// </summary>
        /// <param name="buffer">DVBuffer where the properties are read</param>
        public void ReadProperties(DVBuffer buffer)
        {
            ProprietesWpf property;

            buffer.Get(out property);
            while (property != ProprietesWpf.IMAGE_FIN)
            {
                switch (property)
                {
                    case ProprietesWpf.PRESENTATION_DEBUT:								//début présentation
                        if (Presentation == null) Presentation = new XHtmlPresentation(this);
                        Presentation.ReadProperties(buffer);
                        Presentation.SetProperties();
                        break;

                    case ProprietesWpf.IMAGE_IMAGE_DEBUT:
                        XHtmlImageFile imageFile = new XHtmlImageFile();
                        imageFile.ReadProperties(buffer);
                        //Source = GetImage(imageFile);
                        break;

                    case ProprietesWpf.IMAGE_TRAITEMENT:								//type de traitement (byte)
                        byte stretchCode;
                        buffer.Get(out stretchCode);
                        stretchMode = (StretchMode)stretchCode;
                        SetStretch();
                        break;
                }

                buffer.Get(out property);
            }
        }
Ejemplo n.º 23
0
        private void AddVertexDataDeformed(
            SplineData spline, Mesh mesh, StretchMode stretch, AlignMode align,
            float stretchFactor, float meshStart, float minZ, Vector3 center,
            List <Vector3> vertices, List <Vector3> normals, List <Vector2> uvs)
        {
            Vector3[] inVerts   = mesh.vertices;
            Vector3[] inNormals = mesh.normals;
            Vector2[] inUvs     = uvs != null ? mesh.uv : null;

            float centerPos      = Mathf.Clamp01(meshStart + (center.z - minZ) / spline.length);
            var   centerRotation = spline.GetRotation(centerPos);

            if (align == AlignMode.ForceUpright)
            {
                centerRotation = Quaternion.Euler(0, centerRotation.eulerAngles.y, 0);
            }
            else if (align == AlignMode.NoRotation)
            {
                centerRotation = Quaternion.identity;
            }

            Vector3 centerOffset = spline.GetPoint(centerPos) + (centerRotation * Vector3.forward * minZ);

            Matrix4x4 alignMatrix = Matrix4x4.TRS(centerOffset, centerRotation, Vector3.one);

            for (int i = 0; i < inVerts.Length; i++)
            {
                var vert   = inVerts[i];
                var normal = inNormals[i];
                var uv     = Vector2.zero;
                if (inUvs != null && inUvs.Length > i)
                {
                    uv = inUvs[i];
                }

                vert.z -= minZ;
                if ((stretch & StretchMode.Mesh) == StretchMode.Mesh)
                {
                    vert.z *= stretchFactor;
                }

                if (align == AlignMode.Deform)
                {
                    float pos  = Mathf.Clamp01(meshStart + (vert.z / spline.length));
                    var   srot = spline.GetRotation(pos);
                    var   spos = spline.GetPoint(pos);

                    vert   = spos + (srot * Vector3.ProjectOnPlane(vert, Vector3.forward));
                    normal = srot * normal;
                }
                else
                {
                    vert = alignMatrix.MultiplyPoint(vert);

                    normal = alignMatrix.MultiplyVector(normal);
                }

                vertices.Add(vert);
                normals.Add(normal);
                if (uvs != null)
                {
                    uvs.Add(uv);
                }
            }
        }
Ejemplo n.º 24
0
 public void SetStretchMode(StretchMode newMode, out StretchMode oldMode)
 {
     oldMode = Gdi.SetStretchBltMode(this, newMode);
 }
Ejemplo n.º 25
0
        public void resize_image_using_sampler(string filename, int width, int?height, StretchMode mode, IImageSampler sampler)
        {
            var image = Image.Load($"TestImages/{ filename }");
            var watch = Stopwatch.StartNew();

            if (height != null)
            {
                image = image.Resize(width, height.Value, mode, sampler);
            }
            else
            {
                image = image.Resize(width, mode, sampler);
            }

            Trace.WriteLine($"{ sampler.GetType().Name }: { watch.ElapsedMilliseconds}ms");

            height = height ?? width;


            var outputFile = $"TestResult/Resized/{ Path.GetFileNameWithoutExtension(filename) }.{ mode }.{ sampler.GetType().Name }.{ width }x{ height }.jpg";

            image.VerifyAndSave(outputFile);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Calculate pan and zoom matrix based on provided streatch mode.
        /// </summary>
        /// <param name="panelWidth">The panel width.</param>
        /// <param name="panelHeight">The panel height.</param>
        /// <param name="elementWidth">The element width.</param>
        /// <param name="elementHeight">The element height.</param>
        /// <param name="mode">The stretch mode.</param>
        public static Matrix CalculateMatrix(double panelWidth, double panelHeight, double elementWidth, double elementHeight, StretchMode mode)
        {
            var zx = panelWidth / elementWidth;
            var zy = panelHeight / elementHeight;
            var cx = elementWidth / 2.0;
            var cy = elementHeight / 2.0;

            switch (mode)
            {
            default:
            case StretchMode.None:
                return(Matrix.Identity);

            case StretchMode.Fill:
                return(MatrixHelper.ScaleAt(zx, zy, cx, cy));

            case StretchMode.Uniform:
            {
                var zoom = Min(zx, zy);
                return(MatrixHelper.ScaleAt(zoom, zoom, cx, cy));
            }

            case StretchMode.UniformToFill:
            {
                var zoom = Max(zx, zy);
                return(MatrixHelper.ScaleAt(zoom, zoom, cx, cy));
            }
            }
        }
Ejemplo n.º 27
0
 public StretchModeEntry(string text, StretchMode mode)
 {
     Text = text ?? throw new ArgumentNullException(nameof(text));
     Mode = mode;
 }
Ejemplo n.º 28
0
        public bool LoadSprite(XElement spriteValues, string graphicDirectory, out string reason)
        {
            string filename = null;
            Name = null;
            foreach (var attribute in spriteValues.Attributes())
            {
                //Get the graphic file
                switch (attribute.Name.ToString().ToLower())
                {
                    case "file":
                    {
                        filename = attribute.Value;
                        break;
                    }
                    case "name":
                    {
                        Name = attribute.Value;
                        break;
                    }
                    case "stretchmode":
                    {
                        if (attribute.Value == "repeat")
                        {
                            stretchMode = StretchMode.REPEAT;
                        }
                        break;
                    }
                }
            }
            if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(filename))
            {
                reason = "No sprite name or file location.";
                return false;
            }
            Sprite graphicFile;
            if (ImageCache.Images.Contains(Name))
            {
                graphicFile = new Sprite(Name, ImageCache.Images[Name]);
            }
            else
            {
                string path = Path.Combine(graphicDirectory, filename);
                if (!File.Exists(path))
                {
                    reason = "Graphic File doesn't exist: " + path;
                    return false;
                }
                graphicFile = new Sprite(Name, Image.FromFile(Path.Combine(graphicDirectory, filename)));
            }

            int frameCount = 0;
            foreach (var element in spriteValues.Elements())
            {
                int x = 0;
                int y = 0;
                int width = 0;
                int height = 0;
                int axisX = 0;
                int axisY = 0;
                string frameLength = null;
                //Process each frame
                foreach (var attribute in element.Attributes())
                {
                    switch (attribute.Name.ToString().ToLower())
                    {
                        case "x":
                        {
                            x = int.Parse(attribute.Value);
                            break;
                        }
                        case "y":
                        {
                            y = int.Parse(attribute.Value);
                            break;
                        }
                        case "width":
                        {
                            width = int.Parse(attribute.Value);
                            break;
                        }
                        case "height":
                        {
                            height = int.Parse(attribute.Value);
                            break;
                        }
                        case "framelength":
                        {
                            frameLength = attribute.Value;
                            break;
                        }
                        case "axisx":
                        {
                            axisX = int.Parse(attribute.Value);
                            break;
                        }
                        case "axisy":
                        {
                            axisY = int.Parse(attribute.Value);
                            break;
                        }
                    }
                }
                var frame = new Sprite(Name + frameCount, graphicFile.Image, x, y, width, height, axisX,
                                                              axisY);
                if (stretchMode == StretchMode.REPEAT)
                {
                    frame.WrapMode = ImageAddressing.Wrapping;
                }
                Frames.Add(frame);
                FrameLength.Add(frameLength);
                frameCount++;
            }
            reason = null;
            return true;
        }
Ejemplo n.º 29
0
 public static Image Height(this Image source, int height, int width = -1, StretchMode mode = StretchMode.Fill, IImageSampler sampler = null)
     => Resize(source, width >= 0 ? width : (int)Math.Round(height * source.AspectRatio), height, mode, sampler);
Ejemplo n.º 30
0
 private static extern bool SetStretchBltMode(IntPtr hdc, StretchMode iStretchMode);
Ejemplo n.º 31
0
 public void SetStretchBltMode(StretchMode stretchMode)
 {
     _currentState.StretchBltMode = stretchMode;
 }