Encapsulation of the ImageMagick geometry object.
예제 #1
1
        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new CropTransformViewModel(configData);
            using (MagickImage image = new MagickImage(infile))
            {
                if (conf.FromLiveView && ServiceProvider.DeviceManager.SelectedCameraDevice != null)
                {
                    var prop = ServiceProvider.DeviceManager.SelectedCameraDevice.LoadProperties();
                    conf.Left = (int) (image.Width*prop.LiveviewSettings.HorizontalMin/100);
                    conf.Width = (image.Width*
                                  (prop.LiveviewSettings.HorizontalMax - prop.LiveviewSettings.HorizontalMin)/100);
                    conf.Top = (image.Height*prop.LiveviewSettings.VerticalMin/100);
                    conf.Height = (image.Height*(prop.LiveviewSettings.VerticalMax - prop.LiveviewSettings.VerticalMin)/
                                   100);
                }
                if (conf.CropMargins)
                {
                    conf.Left = image.Width * conf.WidthProcent / 100;
                    conf.Width = image.Width - (conf.Left*2);
                    conf.Top = image.Height * conf.HeightProcent / 100;
                    conf.Height = image.Height - (conf.Top*2);
                }

                MagickGeometry geometry = new MagickGeometry();
                geometry.Width = conf.Width;
                geometry.Height = conf.Height;
                geometry.X = conf.Left;
                geometry.Y = conf.Top;
                image.Crop(geometry);
                image.Format = MagickFormat.Jpeg;
                image.Write(dest);
            }
            return dest;
        }
예제 #2
0
        private void crop_images()
        {
            foreach (var s in sheet.sprites)
            {
                using (MagickImage image_a = new MagickImage(alphaPath))
                {
                    using (MagickImage image_rgb = new MagickImage(rgbPath))
                    {
                        var g = new ImageMagick.MagickGeometry(s.x, s.y, s.w, s.h);
                        image_a.Crop(g);

                        image_rgb.Crop(g);
                        image_rgb.Composite(image_a, CompositeOperator.CopyAlpha);
                        int i = 1;
                        while (i < Math.Max(s.w, s.h))
                        {
                            i = i * 2;
                        }
                        image_rgb.Extent(new MagickGeometry(-(i / 2 - s.w / 2), -(i / 2 - s.h / 2), i, i), MagickColor.FromRgba(255, 255, 255, 0));
                        image_rgb.Write(folderPath + "/" + s.n);
                    }
                }
                //return;
            }
        }
예제 #3
0
    internal static Wrapper.MagickGeometry GetInstance(MagickGeometry value)
    {
      if (value == null)
        return null;

      return value._Instance;
    }
예제 #4
0
파일: PdfCov.cs 프로젝트: Centny/cswf.doc
        public PdfCov(String src, String dst_f, int maxw = 768, int maxh = 1024, double densityx = 96, double densityy = 96, int beg = 0) : base(src, dst_f, maxw, maxh, beg)
        {

            this.DensityX = densityx;
            this.DensityY = densityy;
            this.size = new MagickGeometry(maxw, maxh);
            this.size.Greater = true;
            this.settings = new MagickReadSettings();
            this.settings.Density = new PointD(this.DensityX, this.DensityY);
        }
예제 #5
0
    ///<summary>
    /// Creates a new DrawableCompositeImage instance.
    ///</summary>
    ///<param name="offset">The offset from origin.</param>
    ///<param name="image">The image to draw.</param>
    public DrawableCompositeImage(MagickGeometry offset, MagickImage image)
      : this(image)
    {
      Throw.IfNull("offset", offset);

      X = offset.X;
      Y = offset.Y;
      Width = offset.Width;
      Height = offset.Height;
      Compose = CompositeOperator.CopyAlpha;
    }
예제 #6
0
        ///<summary>
        /// Creates a new DrawableCompositeImage instance.
        ///</summary>
        ///<param name="offset">The offset from origin.</param>
        ///<param name="compose">The algorithm to use.</param>
        ///<param name="image">The image to draw.</param>
        public DrawableCompositeImage(MagickGeometry offset, CompositeOperator compose, MagickImage image)
            : this(image)
        {
            Throw.IfNull("offset", offset);

            X       = offset.X;
            Y       = offset.Y;
            Width   = offset.Width;
            Height  = offset.Height;
            Compose = compose;
        }
예제 #7
0
    public void Test_Rectangle()
    {
      var rectangle = new Rectangle(1, 2, 3, 4);

      var geometry = new MagickGeometry(rectangle);
      Assert.AreEqual(1, geometry.X);
      Assert.AreEqual(2, geometry.Y);
      Assert.AreEqual(3, geometry.Width);
      Assert.AreEqual(4, geometry.Height);

      Assert.AreEqual(geometry,  (MagickGeometry)rectangle);
    }
예제 #8
0
        public string Execute(FileItem fileItem,string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new ResizeTransformViewModel(configData);
            dest = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest) + ".jpg");
            using (MagickImage image = new MagickImage(infile))
            {
                MagickGeometry geometry = new MagickGeometry(conf.Width, conf.Height);
                geometry.IgnoreAspectRatio = !conf.KeepAspect;

                image.Resize(geometry);
                image.Format = MagickFormat.Jpeg;
                image.Write(dest);
            }
            return dest;
        }
예제 #9
0
    public static MagickRectangle FromGeometry(MagickGeometry geometry, MagickImage image)
    {
      if (geometry == null)
        return null;

      int width = geometry.Width;
      int height = geometry.Height;

      if (geometry.IsPercentage)
      {
        width = image.Width * new Percentage(geometry.Width);
        height = image.Height * new Percentage(geometry.Height);
      }

      return new MagickRectangle(geometry.X, geometry.Y, width, height);
    }
예제 #10
0
    public static void ResizeToFixedSize()
    {
      // Read from file
      using (MagickImage image = new MagickImage(SampleFiles.SnakewarePng))
      {
        MagickGeometry size = new MagickGeometry(100, 100);
        // This will resize the image to a fixed size without maintaining the aspect ratio.
        // Normally an image will be resized to fit inside the specified size.
        size.IgnoreAspectRatio = true;

        image.Resize(size);

        // Save the result
        image.Write(SampleFiles.OutputDirectory + "Snakeware.100x100.png");
      }
    }
예제 #11
0
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="other">The object to compare this geometry with.</param>
        /// <returns>A signed number indicating the relative values of this instance and value.</returns>
        public int CompareTo(MagickGeometry other)
        {
            if (other is null)
            {
                return(1);
            }

            int left  = Width * Height;
            int right = other.Width * other.Height;

            if (left == right)
            {
                return(0);
            }

            return(left < right ? -1 : 1);
        }
예제 #12
0
        ///<summary>
        /// Compares the current instance with another object of the same type.
        ///</summary>
        ///<param name="other">The object to compare this geometry with.</param>
        public int CompareTo(MagickGeometry other)
        {
            if (ReferenceEquals(other, null))
            {
                return(1);
            }

            int left  = (this.Width * this.Height);
            int right = (other.Width * other.Height);

            if (left == right)
            {
                return(0);
            }

            return(left < right ? -1 : 1);
        }
예제 #13
0
        public static MagickRectangle FromGeometry(MagickGeometry geometry, MagickImage image)
        {
            if (geometry == null)
            {
                return(null);
            }

            int width  = geometry.Width;
            int height = geometry.Height;

            if (geometry.IsPercentage)
            {
                width  = image.Width * new Percentage(geometry.Width);
                height = image.Height * new Percentage(geometry.Height);
            }

            return(new MagickRectangle(geometry.X, geometry.Y, width, height));
        }
예제 #14
0
        private INativeInstance CreateNativeInstance()
        {
            string format   = GetFormat();
            string fileName = FileName;

            if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(format))
            {
                fileName = format + ":" + fileName;
            }

            NativeMagickSettings instance = new NativeMagickSettings();

            instance.BackgroundColor   = BackgroundColor;
            instance.ColorSpace        = ColorSpace;
            instance.ColorType         = ColorType;
            instance.CompressionMethod = CompressionMethod;
            instance.Debug             = Debug;
            instance.Density           = Density != null?Density.ToString(DensityUnit.Undefined) : null;

            instance.Endian        = Endian;
            instance.Font          = _Font;
            instance.FontPointsize = _FontPointsize;
            instance.Format        = format;
            instance.Interlace     = Interlace;
            instance.Monochrome    = Monochrome;
            instance.Verbose       = Verbose;

            instance.SetColorFuzz(ColorFuzz);
            instance.SetFileName(fileName);
            instance.SetNumberScenes(NumberScenes);
            instance.SetPage(MagickGeometry.ToString(Page));
            instance.SetPing(Ping);
            instance.SetQuality(Quality);
            instance.SetScene(Scene);
            instance.SetScenes(Scenes);
            instance.SetSize(Size);

            foreach (string key in _Options.Keys)
            {
                instance.SetOption(key, _Options[key]);
            }

            return(instance);
        }
예제 #15
0
        internal MagickSettings()
        {
            using (NativeMagickSettings instance = new NativeMagickSettings())
            {
                BackgroundColor = instance.BackgroundColor;
                ColorSpace      = instance.ColorSpace;
                ColorType       = instance.ColorType;
                Compression     = instance.Compression;
                Debug           = instance.Debug;
                Density         = Density.Create(instance.Density);
                Endian          = instance.Endian;
                Extract         = MagickGeometry.FromString(instance.Extract);
                _font           = instance.Font;
                _fontPointsize  = instance.FontPointsize;
                Format          = EnumHelper.Parse(instance.Format, MagickFormat.Unknown);
                Interlace       = instance.Interlace;
                Monochrome      = instance.Monochrome;
                Verbose         = instance.Verbose;
            }

            Drawing = new DrawingSettings();
        }
예제 #16
0
        internal static MagickGeometry Clone(MagickGeometry value)
        {
            if (value == null)
            {
                return(null);
            }

            return(new MagickGeometry()
            {
                AspectRatio = value.AspectRatio,
                FillArea = value.FillArea,
                Greater = value.Greater,
                Height = value.Height,
                IgnoreAspectRatio = value.IgnoreAspectRatio,
                IsPercentage = value.IsPercentage,
                Less = value.Less,
                LimitPixels = value.LimitPixels,
                Width = value.Width,
                X = value.X,
                Y = value.Y,
            });
        }
예제 #17
0
        ///<summary>
        /// Determines whether the specified geometry is equal to the current geometry.
        ///</summary>
        ///<param name="other">The geometry to compare this geometry with.</param>
        public bool Equals(MagickGeometry other)
        {
            if (ReferenceEquals(other, null))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                (Width == other.Width &&
                 Height == other.Height &&
                 X == other.X &&
                 Y == other.Y &&
                 IsPercentage == other.IsPercentage &&
                 IgnoreAspectRatio == other.IgnoreAspectRatio &&
                 Less == other.Less &&
                 Greater == other.Greater &&
                 FillArea == other.FillArea &&
                 LimitPixels == other.LimitPixels);
        }
예제 #18
0
        public static List<PartOfImage> PartOfImage(string ImgUrl, string onlyFileName, int pxFormat)
        {
            List<PartOfImage> ImgsInfo = new List<Api._QPR.PartOfImage>();
            //resize with pixformat
            MagickImage img = new MagickImage(ImgUrl);
            int _w = img.Width;
            int _h = img.Height;

            int partWComp = (_w / UserProperty.ComputerNumber);
            int partHComp = (_h / UserProperty.ComputerNumber);

            int PartWPixFormat = (partWComp / pxFormat);
            int PartHPixFormat = (partHComp / pxFormat);

            int newPartWcomp = PartWPixFormat * pxFormat;
            int newPartHcomp = PartHPixFormat * pxFormat;

            int newW = newPartWcomp * UserProperty.ComputerNumber;
            int newH = newPartHcomp * UserProperty.ComputerNumber;

            String newGeomStr = newW.ToString() + "x" + newH.ToString();
            MagickGeometry intermediate_geo = new MagickGeometry(newGeomStr);
            img.Crop(intermediate_geo);

            string partImgFolder = Path.Combine(UserProperty.ResourcePhotos_Path, "ImagePart");
            if (!Directory.Exists(partImgFolder))
            {
                Directory.CreateDirectory(partImgFolder);
            }
            if (_w >= _h)
            {
                int cont = 0;
                do
                {
                    Rectangle recti = new Rectangle(cont * (newW / UserProperty.ComputerNumber), 0, (newW / UserProperty.ComputerNumber), newH);
                    MagickGeometry intermediate_geo1 = new MagickGeometry(recti);
                    MagickImage newPartImg = img.Clone();
                    newPartImg.Crop(intermediate_geo1);
                    string file = Path.Combine(partImgFolder, "output_" + cont + ImageProperty.JPG);
                    newPartImg.Write(file);
                    ImgsInfo.Add(new Api._QPR.PartOfImage(file, recti));
                    cont++;
                } while (cont < UserProperty.ComputerNumber);
            }
            else
            {
                int cont = 0;
                do
                {
                    Rectangle recti = new Rectangle(0, cont * (newH / UserProperty.ComputerNumber), newW, (newH / UserProperty.ComputerNumber));
                    MagickGeometry intermediate_geo1 = new MagickGeometry(recti);
                    MagickImage newPartImg = img.Clone();
                    newPartImg.Crop(intermediate_geo1);
                    string file = Path.Combine(partImgFolder, onlyFileName + "_" + cont + ImageProperty.JPG);
                    newPartImg.Write(file);
                    ImgsInfo.Add(new Api._QPR.PartOfImage(file, recti));
                    cont++;
                } while (cont < UserProperty.ComputerNumber);
            }
            return ImgsInfo;
            //img.Write(UserProperty.ResourcePhotos_Path + "\\" + imgNamei + "1" + ImageProperty.JPG);
            //////////////////////////////////////////
        }
예제 #19
0
 internal static string ToString(MagickGeometry value)
 {
     return(value?.ToString());
 }
예제 #20
0
 protected MagickImage takeSnapshot(IWebElement webElement, int offset)
 {
     try
     {
         Screenshot image = ((ITakesScreenshot)pageManager.driver).GetScreenshot();
         MagickImage MImage = new MagickImage(image.AsByteArray);
         Point coords = (webElement as ILocatable).LocationOnScreenOnceScrolledIntoView;
         // MagickGeometry n = new MagickGeometry(webElement.Location.X - offset, webElement.Location.Y - offset, webElement.Size.Width + 2 * offset, webElement.Size.Height + 2 * offset);
         MagickGeometry n = new MagickGeometry(coords.X - offset, coords.Y - offset, webElement.Size.Width + 2 * offset, webElement.Size.Height + 2 * offset);
         MImage.Crop(n);
         return MImage;
     }
     catch
     {
         Console.Out.WriteLine("Ошибка при снятии скриншота");
         return null;
     }
 }
예제 #21
0
 public virtual ushort[] ToShortArray(MagickGeometry geometry, PixelMapping mapping) => ToShortArray(geometry, mapping.ToString());
예제 #22
0
 public virtual byte[] ToByteArray(MagickGeometry geometry, PixelMapping mapping) => ToByteArray(geometry.X, geometry.Y, geometry.Width, geometry.Height, mapping.ToString());
예제 #23
0
 public virtual void SetArea(MagickGeometry geometry, QuantumType[] values) => SetArea(geometry.X, geometry.Y, geometry.Width, geometry.Height, values);
예제 #24
0
        public override ushort[] ToShortArray(MagickGeometry geometry, string mapping)
        {
            Throw.IfNull(nameof(geometry), geometry);

            return(base.ToShortArray(geometry, mapping));
        }
예제 #25
0
    public void Test_IEquatable()
    {
      MagickGeometry first = new MagickGeometry(10, 5);

      Assert.IsFalse(first == null);
      Assert.IsFalse(first.Equals(null));
      Assert.IsTrue(first.Equals(first));
      Assert.IsTrue(first.Equals((object)first));

      MagickGeometry second = new MagickGeometry(10, 5);

      Assert.IsTrue(first == second);
      Assert.IsTrue(first.Equals(second));
      Assert.IsTrue(first.Equals((object)second));

      second = new MagickGeometry(5, 5);

      Assert.IsTrue(first != second);
      Assert.IsFalse(first.Equals(second));
    }
예제 #26
0
    ///<summary>
    /// Determines whether the specified geometry is equal to the current geometry.
    ///</summary>
    ///<param name="other">The geometry to compare this geometry with.</param>
    public bool Equals(MagickGeometry other)
    {
      if (ReferenceEquals(other, null))
        return false;

      if (ReferenceEquals(this, other))
        return true;

      return
        Width == other.Width &&
        Height == other.Height &&
        X == other.X &&
        Y == other.Y &&
        IsPercentage == other.IsPercentage &&
        IgnoreAspectRatio == other.IgnoreAspectRatio &&
        Less == other.Less &&
        Greater == other.Greater &&
        FillArea == other.FillArea &&
        LimitPixels == other.LimitPixels;
    }
예제 #27
0
    ///<summary>
    /// Compares the current instance with another object of the same type.
    ///</summary>
    ///<param name="other">The object to compare this geometry with.</param>
    public int CompareTo(MagickGeometry other)
    {

      if (ReferenceEquals(other, null))
        return 1;

      int left = (this.Width * this.Height);
      int right = (other.Width * other.Height);

      if (left == right)
        return 0;

      return left < right ? -1 : 1;
    }
예제 #28
0
    public void Test_ToString()
    {
      MagickGeometry geometry = new MagickGeometry(10, 5);
      Assert.AreEqual("10x5", geometry.ToString());

      geometry = new MagickGeometry(-5, 5, 10, 20);
      Assert.AreEqual("10x20-5+5", geometry.ToString());

      geometry = new MagickGeometry(5, -5, 10, 20);
      Assert.AreEqual("10x20+5-5", geometry.ToString());

      geometry = new MagickGeometry(geometry.ToString());
      Assert.AreEqual(5, geometry.X);
      Assert.AreEqual(-5, geometry.Y);
      Assert.AreEqual(10, geometry.Width);
      Assert.AreEqual(20, geometry.Height);
    }
예제 #29
0
        //public DateTime s_局部高清_處理方式 = DateTime.Now;

        /// <summary>
        ///
        /// </summary>
        public void func_局部高清_初始化()
        {
            String s_path     = ""; //圖片路徑
            double d_倍率       = 1;  //縮放倍率
            double d_倍率_old   = 1;  //超過500毫秒沒有進行縮放才重新算圖
            double d_x        = 1;  //圖片位置
            double d_y        = 1;
            double d_window_w = 1;  //視窗寬度
            double d_window_h = 1;
            int    int_旋轉角度   = 0;
            bool   bool_剪裁    = false;

            DateTime time_避免捲動中算圖 = DateTime.Now;//



            //-------------

            new Thread(() => {
                while (bool_程式運行中)
                {
                    //-------------

                    Thread.Sleep(100);

                    if (u_大量瀏覽模式 != null)
                    {
                        s_path = "";
                        continue;
                    }

                    if (bool_啟動局部高清 == false)
                    {
                        s_path = "";
                        continue;
                    }

                    //在程式預設開啟的資料夾不啟用
                    if (int_目前圖片位置 < ar_path.Count)
                    {
                        if (ar_path[int_目前圖片位置].IndexOf(fun_執行檔路徑() + "\\data\\imgs") == 0)
                        {
                            s_path = "";
                            continue;
                        }
                    }

                    /*
                     * if (this.Visibility != Visibility.Visible) {
                     *  //s_path = "";
                     *  Thread.Sleep(100);
                     *  continue;
                     * }*/


                    /*
                     * if (s_img_type_附檔名 == "PNG" || s_img_type_附檔名 == "JPG" ||
                     *  s_img_type_附檔名 == "TIF" || s_img_type_附檔名 == "BMP" ||
                     *  image_局部高清 != null) {
                     *
                     * } else {
                     *  continue;
                     * }*/



                    bool bool_重新繪製      = false;
                    bool bool_新圖片       = false;
                    bool bool_不剪裁且不重新繪製 = false;


                    C_adapter.fun_UI執行緒(() => {
                        try {
                            if (d_倍率 == img.ActualWidth && bool_剪裁 == false)
                            {
                                //System.Console.WriteLine("不剪裁且不重新繪製: " + ar_path[int_目前圖片位置]);
                                bool_不剪裁且不重新繪製 = true;
                            }

                            if (s_path != ar_path[int_目前圖片位置])
                            {
                                //System.Console.WriteLine("新圖片: " + ar_path[int_目前圖片位置]);

                                s_path         = ar_path[int_目前圖片位置];
                                bool_新圖片       = true;
                                bool_不剪裁且不重新繪製 = false;
                                bool_重新繪製      = true;

                                //讓新圖片一定能立即運算
                                d_倍率     = 0.123456;
                                d_倍率_old = img.ActualWidth;
                            }

                            if (d_倍率_old == img.ActualWidth)
                            {
                                //bool_重新繪製 = false;

                                if (d_倍率 != img.ActualWidth ||
                                    d_x != scrollviewer_1.ContentHorizontalOffset || d_y != scrollviewer_1.ContentVerticalOffset ||
                                    d_window_w != this.ActualWidth || d_window_h != this.ActualHeight ||
                                    int_旋轉角度 != c_旋轉.int_旋轉)
                                {
                                    d_倍率 = img.ActualWidth;

                                    d_x        = scrollviewer_1.ContentHorizontalOffset;
                                    d_y        = scrollviewer_1.ContentVerticalOffset;
                                    d_window_w = this.ActualWidth;
                                    d_window_h = this.ActualHeight;
                                    int_旋轉角度   = c_旋轉.int_旋轉;

                                    bool_重新繪製 = true;
                                }
                            }

                            if (((TimeSpan)(DateTime.Now - time_避免捲動中算圖)).TotalMilliseconds < 800)  //連點低於400毫秒

                            {
                            }
                            else
                            {
                                d_倍率_old     = img.ActualWidth;
                                time_避免捲動中算圖 = DateTime.Now;
                            }
                        } catch {
                            s_path    = "";
                            bool_重新繪製 = false;
                            return;
                        }
                    });


                    if (bool_不剪裁且不重新繪製)
                    {
                        continue;
                    }
                    if (bool_重新繪製 == false)
                    {
                        continue;
                    }



                    if (bool_新圖片)
                    {
                        try {
                            if (File.Exists(ar_path[int_目前圖片位置]))
                            {
                                if (image_局部高清 == null)
                                {
                                    var im5 = new ImageMagick.MagickImage((ar_path[int_目前圖片位置]));
                                    //

                                    //如果讀取完圖片後,使用者已經切換到其他圖片,就不要寫入到「image_局部高清」,直接解析新圖片
                                    if (int_目前圖片位置 < 0 || int_目前圖片位置 >= ar_path.Count || s_path != ar_path[int_目前圖片位置])
                                    {
                                        image_局部高清 = null;
                                        s_path     = null;
                                        im5        = null;
                                        continue;
                                    }
                                    else
                                    {
                                        image_局部高清 = im5;
                                    }

                                    //System.Console.WriteLine("一般  " + s_path);
                                }
                                else
                                {
                                    //image_局部高清 = new ImageMagick.MagickImage((ar_path[int_目前圖片位置]));
                                    //System.Console.WriteLine("特殊 " + s_path);
                                }


                                //https://www.smashingmagazine.com/2015/06/efficient-image-resizing-with-imagemagick/
                                //不使用 漸進式渲染
                                image_局部高清.Interlace = Interlace.NoInterlace;


                                //剝離所有配置文件和註釋的圖像。
                                image_局部高清.Strip();

                                //雙線性插值
                                //image_局部高清.FilterType = FilterType.Hann;
                            }
                            else
                            {
                                s_path = "";
                                continue;
                            }
                        } catch {
                            s_path = "";
                            System.Console.WriteLine("*******局部高清 失敗");
                            continue;
                        }
                    }

                    //避免已經切換到其他圖片
                    if (int_目前圖片位置 < 0 || int_目前圖片位置 >= ar_path.Count)
                    {
                        continue;
                    }
                    if (d_倍率 != img.ActualWidth || s_path != ar_path[int_目前圖片位置])
                    {
                        continue;
                    }
                    if (bool_啟動局部高清 == false)
                    {
                        s_path = "";
                        continue;
                    }

                    double w03    = 1;
                    double h03    = 1;
                    double l03    = 1;
                    double t03    = 1;
                    double d_縮放倍率 = 1;

                    C_adapter.fun_UI執行緒(() => {
                        w03 = scrollviewer_1.ViewportWidth;
                        h03 = scrollviewer_1.ViewportHeight;
                        l03 = scrollviewer_1.ContentHorizontalOffset;
                        t03 = scrollviewer_1.ContentVerticalOffset;

                        if (c_旋轉.bool_垂直鏡像)
                        {
                            t03 = scrollviewer_1.ScrollableHeight - t03;
                        }
                        if (c_旋轉.bool_水平鏡像)
                        {
                            l03 = scrollviewer_1.ScrollableWidth - l03;
                        }

                        if (c_旋轉.int_旋轉 == 0)
                        {
                            if (w03 > grid_img.ActualWidth)
                            {
                                w03 = grid_img.ActualWidth;
                            }
                            if (h03 > grid_img.ActualHeight)
                            {
                                h03 = grid_img.ActualHeight;
                            }
                        }

                        if (c_旋轉.int_旋轉 == 180)
                        {
                            if (w03 > grid_img.ActualWidth)
                            {
                                w03 = grid_img.ActualWidth;
                            }
                            if (h03 > grid_img.ActualHeight)
                            {
                                h03 = grid_img.ActualHeight;
                            }
                            l03 = scrollviewer_1.ScrollableWidth - l03;
                            t03 = scrollviewer_1.ScrollableHeight - t03;
                        }

                        if (c_旋轉.int_旋轉 == 90)
                        {
                            if (w03 > grid_img.ActualWidth)
                            {
                                h03 = grid_img.ActualHeight;
                            }
                            else
                            {
                                h03 = scrollviewer_1.ViewportWidth;
                            }

                            if (h03 > grid_img.ActualHeight)
                            {
                                w03 = grid_img.ActualWidth;
                            }
                            else
                            {
                                w03 = scrollviewer_1.ViewportHeight;
                            }

                            var zzz2 = scrollviewer_1.ScrollableWidth - l03;
                            l03      = t03;
                            t03      = zzz2;
                        }

                        if (c_旋轉.int_旋轉 == 270)
                        {
                            if (w03 > grid_img.ActualWidth)
                            {
                                h03 = grid_img.ActualHeight;
                            }
                            else
                            {
                                h03 = scrollviewer_1.ViewportWidth;
                            }

                            if (h03 > grid_img.ActualHeight)
                            {
                                w03 = grid_img.ActualWidth;
                            }
                            else
                            {
                                w03 = scrollviewer_1.ViewportHeight;
                            }

                            var zzz2 = l03;
                            l03      = scrollviewer_1.ScrollableHeight - t03;
                            t03      = zzz2;
                        }
                    });


                    w03 += 50;
                    h03 += 50;

                    //避免圖片還沒完全載入
                    Thread.Sleep(30);


                    //複製物件
                    ImageMagick.IMagickImage ii = null;


                    try {
                        /*if (image_局部高清_50 != null && img.ActualWidth < int_img_w / 2) {
                         *  ii = image_局部高清_50.Clone();
                         * } else {*/
                        if (image_局部高清 == null)
                        {
                            continue;
                        }
                        ii = image_局部高清.Clone();
                        //}


                        //計算縮放比例
                        if (img.ActualWidth > img.ActualHeight)
                        {
                            d_縮放倍率 = img.ActualWidth / ii.Width;
                        }
                        else
                        {
                            d_縮放倍率 = img.ActualHeight / ii.Height;
                        }


                        bool_剪裁 = false;
                        if (d_縮放倍率 * int_img_w > 5000 || d_縮放倍率 * int_img_h > 5000)
                        {
                            bool_剪裁 = true;

                            //剪裁
                            ii.Crop(new MagickGeometry(
                                        (int)(l03 / d_縮放倍率),
                                        (int)(t03 / d_縮放倍率),
                                        (int)(w03 / d_縮放倍率),
                                        (int)(h03 / d_縮放倍率))
                                    );
                        }


                        //縮放
                        var mg    = new ImageMagick.MagickGeometry();
                        mg.Height = (int)(ii.Height * d_縮放倍率);
                        mg.Width  = (int)(ii.Width * d_縮放倍率);

                        DateTime time_start = DateTime.Now;//計時開始 取得目前時間


                        if (int_高品質成像模式 == 1 || int_高品質成像模式 == 4)
                        {
                            ii.Resize(mg);//縮放圖片-快
                            if (d_縮放倍率 < 1)
                            {
                                ii.UnsharpMask(0.8, 0.8);//銳化-快速
                            }
                            //System.Console.WriteLine($"111111111");
                        }

                        if (int_高品質成像模式 == 2)
                        {
                            ii.Resize(mg);//縮放圖片-快
                            if (d_縮放倍率 < 1)
                            {
                                ii.RemoveWriteMask();     //沒有獨立顯卡的電腦,必須用這個語法來延遲,避免圖片顯示不出來
                                ii.UnsharpMask(0.8, 0.8); //銳化-快速
                            }
                            //System.Console.WriteLine($"2222222");
                        }

                        if (int_高品質成像模式 == 3 || int_高品質成像模式 == 3)
                        {
                            ii.Scale(mg);//縮放圖片-慢
                            if (d_縮放倍率 < 1)
                            {
                                ii.Sharpen();//銳化-慢
                            }
                            //System.Console.WriteLine($"3333333");
                        }


                        DateTime time_end = DateTime.Now;                                                     //計時結束 取得目前時間
                        string result2    = ((TimeSpan)(time_end - time_start)).TotalMilliseconds.ToString(); //後面的時間減前面的時間後 轉型成TimeSpan即可印出時間差
                        System.Console.WriteLine("+++++++++++++++++++++++++++++++++++" + result2 + " 毫秒");


                        //ii.Sample(ii.Width,ii.Height);//品質差,速度極快
                        //ii.Extent(mg);//意義不明
                        //ii.Thumbnail(mg.Width, mg.Height);//某些情況下會很慢

                        //縮小圖片後進行銳化

                        /*if (d_縮放倍率 < 1) {
                         *  //ii.RemoveWriteMask();
                         *  //ii.UnsharpMask(0.8, 0.8);
                         *  //ii.UnsharpMask(0.25, 0.25,8,0.065);
                         * }*/


                        //System.Console.WriteLine($"mg {mg.Width}   ii {ii.Width}");

                        //避免已經切換到其他圖片
                        if (int_目前圖片位置 < 0 || int_目前圖片位置 >= ar_path.Count)
                        {
                            continue;
                        }
                        if (d_倍率 != img.ActualWidth || s_path != ar_path[int_目前圖片位置])
                        {
                            continue;
                        }
                        if (bool_啟動局部高清 == false)
                        {
                            s_path = "";
                            continue;
                        }


                        C_adapter.fun_UI執行緒(() => {
                            if (bool_剪裁)
                            {
                                img_局部高清.Margin = new Thickness(
                                    ((int)(l03 / d_縮放倍率)) * d_縮放倍率,
                                    ((int)(t03 / d_縮放倍率)) * d_縮放倍率,
                                    -((int)(l03 / d_縮放倍率)) * d_縮放倍率 - 5000,
                                    -((int)(t03 / d_縮放倍率)) * d_縮放倍率 - 5000
                                    );
                                img_局部高清.Width  = mg.Width;
                                img_局部高清.Height = mg.Height;
                                img_局部高清.Source = ii.ToBitmapSource();
                            }
                            else
                            {
                                img.Source = ii.ToBitmapSource();
                            }
                        });
                    } catch (Exception e) {
                        C_adapter.fun_UI執行緒(() => {
                            MessageBox.Show("局部高清 錯誤 \n" + e.ToString());
                        });
                    }


                    Thread.Sleep(1);



                    C_adapter.fun_UI執行緒(() => {
                        //避免已經切換到其他圖片
                        if (int_目前圖片位置 < 0 || int_目前圖片位置 >= ar_path.Count)
                        {
                            return;
                        }
                        if (d_倍率 != img.ActualWidth || s_path != ar_path[int_目前圖片位置])
                        {
                            return;
                        }
                        if (bool_啟動局部高清 == false)
                        {
                            s_path = "";
                            return;
                        }

                        if (bool_剪裁)
                        {
                            img_局部高清.Visibility = Visibility.Visible;
                            if (ii.IsOpaque == false)
                            {
                                img.Visibility = Visibility.Hidden;
                                //System.Console.WriteLine($"透明");
                            }
                            //System.Console.WriteLine($"剪裁");
                        }
                        else
                        {
                            //System.Console.WriteLine($"原圖");
                            img_局部高清.Visibility = Visibility.Collapsed;
                            img.Visibility      = Visibility.Visible;
                        }
                    });


                    ii.Dispose();
                }
            }).Start();
        }
예제 #30
0
    public void Test_Constructor()
    {
      ExceptionAssert.Throws<ArgumentNullException>(delegate ()
      {
        new MagickGeometry((string)null);
      });

      ExceptionAssert.Throws<ArgumentException>(delegate ()
      {
        new MagickGeometry("");
      });

      MagickGeometry geometry = new MagickGeometry("5x10!");
      Assert.AreEqual(5, geometry.Width);
      Assert.AreEqual(10, geometry.Height);
      Assert.AreEqual(true, geometry.IgnoreAspectRatio);

      geometry = new MagickGeometry("10x5<");
      Assert.AreEqual(10, geometry.Width);
      Assert.AreEqual(5, geometry.Height);
      Assert.AreEqual(true, geometry.Less);

      geometry = new MagickGeometry("5x10>");
      Assert.AreEqual(5, geometry.Width);
      Assert.AreEqual(10, geometry.Height);
      Assert.AreEqual(true, geometry.Greater);

      geometry = new MagickGeometry("10x10^");
      Assert.AreEqual(10, geometry.Width);
      Assert.AreEqual(10, geometry.Height);
      Assert.AreEqual(true, geometry.FillArea);

      geometry = new MagickGeometry("10@");
      Assert.AreEqual(10, geometry.Width);
      Assert.AreEqual(0, geometry.Height);
      Assert.AreEqual(true, geometry.LimitPixels);

      geometry = new MagickGeometry("50%x0>");
      Assert.AreEqual(50, geometry.Width);
      Assert.AreEqual(0, geometry.Height);
      Assert.AreEqual(true, geometry.IsPercentage);
      Assert.AreEqual(true, geometry.Greater);

      geometry = new MagickGeometry(5, 10);
      Assert.AreEqual(5, geometry.Width);
      Assert.AreEqual(10, geometry.Height);

      geometry = new MagickGeometry(5, 10, 15, 20);
      Assert.AreEqual(5, geometry.X);
      Assert.AreEqual(10, geometry.Y);
      Assert.AreEqual(15, geometry.Width);
      Assert.AreEqual(20, geometry.Height);

      geometry = new MagickGeometry(new Percentage(50.0), new Percentage(10.0));
      Assert.AreEqual(50, geometry.Width);
      Assert.AreEqual(10, geometry.Height);
      Assert.AreEqual(true, geometry.IsPercentage);

      geometry = new MagickGeometry(5, 10, (Percentage)15.0, (Percentage)20.0);
      Assert.AreEqual(5, geometry.X);
      Assert.AreEqual(10, geometry.Y);
      Assert.AreEqual(15, geometry.Width);
      Assert.AreEqual(20, geometry.Height);
      Assert.AreEqual(true, geometry.IsPercentage);
    }
예제 #31
0
        public override byte[] ToByteArray(MagickGeometry geometry, PixelMapping mapping)
        {
            Throw.IfNull(nameof(geometry), geometry);

            return(base.ToByteArray(geometry, mapping.ToString()));
        }
예제 #32
0
 /// <summary>
 /// Creates a new DrawableCompositeImage instance.
 /// </summary>
 /// <param name="offset">The offset from origin.</param>
 /// <param name="compose">The algorithm to use.</param>
 /// <param name="image">The image to draw.</param>
 public Drawables Composite(MagickGeometry offset, CompositeOperator compose, MagickImage image)
 {
   _Drawables.Add(new DrawableComposite(offset, compose, image));
   return this;
 }
예제 #33
0
        public override QuantumType[] GetArea(MagickGeometry geometry)
        {
            Throw.IfNull(nameof(geometry), geometry);

            return(base.GetArea(geometry));
        }
예제 #34
0
        /// <summary>
        /// Returns the values of the pixels as an array.
        /// </summary>
        ///<param name="geometry">The geometry of the area.</param>
        ///<param name="mapping">The mapping of the pixels (e.g. RGB/RGBA/ARGB).</param>
        public byte[] ToByteArray(MagickGeometry geometry, string mapping)
        {
            Throw.IfNull("geometry", geometry);

            return(ToByteArray(geometry.X, geometry.Y, geometry.Width, geometry.Height, mapping));
        }
예제 #35
0
 public virtual byte[] ToByteArray(MagickGeometry geometry, string mapping) => ToByteArray(geometry.X, geometry.Y, geometry.Width, geometry.Height, mapping);
예제 #36
0
 internal MagickSearchResult(IMagickImage image, MagickGeometry bestMatch, double similarityMetric)
 {
     SimilarityImage  = image;
     BestMatch        = bestMatch;
     SimilarityMetric = similarityMetric;
 }
예제 #37
0
 public virtual ushort[] ToShortArray(MagickGeometry geometry, string mapping) => ToShortArray(geometry.X, geometry.Y, geometry.Width, geometry.Height, mapping);
예제 #38
0
    public void Test_LiquidRescale()
    {
      using (MagickImage image = new MagickImage(Files.MagickNETIconPNG))
      {
        MagickGeometry geometry = new MagickGeometry(128, 64);
        geometry.IgnoreAspectRatio = true;

        image.LiquidRescale(geometry);
        Assert.AreEqual(128, image.Width);
        Assert.AreEqual(64, image.Height);
      }
    }
예제 #39
0
 public virtual QuantumType[] GetArea(MagickGeometry geometry) => GetArea(geometry.X, geometry.Y, geometry.Width, geometry.Height);
예제 #40
0
        private void DisplayRezisedImage(string file, Actions caseDirectory)
        {
            //put this in a background worker.
            try
            {
                using (MagickImage image = new MagickImage(Path.Combine(Constants.ContainerLocation, Constants.Directories.GetSpecifiedCaseDirectory(caseDirectory), file)))
                {
                    MagickGeometry size = new MagickGeometry(196, 196);
                    size.IgnoreAspectRatio = false;
                    image.Resize(size);
                    this.InvokeIfRequired(() => FilePreviewImage.Image = image.ToBitmap());
                }

          
            }
            catch(Exception e)
            {
                DisplayFileIconWithFileSize(file, caseDirectory);
            }
        }
예제 #41
0
    public void Test_ToPoint()
    {
      PointD point = new MagickGeometry(10, 5).ToPoint();

      Assert.AreEqual(0, point.X);
      Assert.AreEqual(0, point.Y);

      point = new MagickGeometry(1, 2, 3, 4).ToPoint();

      Assert.AreEqual(1, point.X);
      Assert.AreEqual(2, point.Y);
    }
예제 #42
0
        private void Decompose(D3Glyph glyph, int utf32Char)
        {
            string textureName = Path.Combine(dirWithFontTextures, Path.GetFileName(glyph.textureName));
            if (!textures.ContainsKey(textureName))
            {
                string realName = textureName;
                if (!File.Exists(realName))
                {
                    realName = Path.ChangeExtension(textureName, "dds");
                }
                MagickImage newImage = new MagickImage(realName);
                textures[textureName] = newImage;
            }

            MagickImage image = textures[textureName].Clone();

            BMIconInfo icon = new BMIconInfo();
            icon.imageFile = Path.Combine(imageOutputDir, string.Format("{0}_char{1}.tga", font.name, utf32Char));
            icon.charId = utf32Char;

            // baseline position in pixels from top edges of the image
            int baseline = glyph.height - glyph.top; // maybe... maybe it's glyph.imageHeight - glyph.top... and maybe it's something else...

            Debug.Assert(image.Width == 256);
            Debug.Assert(image.Height == 256);
            icon.xoffset = 0;
            //icon.yoffset = font.maxHeight - glyph.top - glyph.bottom; // -baseline;
            icon.yoffset = font.maxTop - glyph.top;
            int xstart = (int)(glyph.s * image.Width + 0.0f); // +glyph.pitch; // this "+ glyph.pitch" is a guess
            int ystart = (int)(glyph.t * image.Height + 0.0f);
            int xend = (int)(glyph.s2 * image.Width - 0.0f);
            int yend = (int)(glyph.t2 * image.Height - 0.0f);
            int glyphWidth = xend - xstart;
            int glyphHeight = yend - ystart;
            Debug.Assert(glyph.imageWidth == glyphWidth);
            Debug.Assert(glyph.imageHeight == glyphHeight);
            xstart += glyph.pitch; // this "+ glyph.pitch" is a guess

            // this damn ImageMagick can't create zero size images!
            if (zeroSizeImage == null)
            {
                if (glyphWidth == 0)
                {
                    glyphWidth = 1;
                }
                if (glyphHeight == 0)
                {
                    glyphHeight = 1;
                }
            }

            icon.xadvance = glyph.xSkip - glyphWidth; // maybe add "- glyph.pitch" here?

            iconInfos[icon.charId] = icon;

            MagickGeometry geom = new MagickGeometry(xstart, ystart, glyphWidth, glyphHeight);
            if (glyphWidth == 0 || glyphHeight == 0)
            {
                //Bitmap bmp = new Bitmap(0, 0, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                var newImage = new MagickImage(zeroSizeImage);
                //newImage.ColorType = image.ColorType;
                //newImage.ColorSpace = image.ColorSpace;
                //image.Crop(1, 0);
                //image.Trim();
                image = newImage;
            }
            else
            {
                image.Crop(geom);
            }
            image.Format = MagickFormat.Tga;
            image.Write(icon.imageFile);
        }
예제 #43
0
 /// <summary>
 /// Adds a new instance of the <see cref="DrawableComposite" /> class to the <see cref="Drawables" />.
 /// </summary>
 /// <param name="offset">The offset from origin.</param>
 /// <param name="image">The image to draw.</param>
 /// <returns>The <see cref="Drawables" /> instance.</returns>
 public Drawables Composite(MagickGeometry offset, IMagickImage image)
 {
     _drawables.Add(new DrawableComposite(offset, image));
     return(this);
 }
예제 #44
0
        public override void SetArea(MagickGeometry geometry, QuantumType[] values)
        {
            Throw.IfNull(nameof(geometry), geometry);

            base.SetArea(geometry, values);
        }
예제 #45
0
 internal MagickSearchResult(MagickImage image, MagickGeometry bestMatch, double similarityMetric)
 {
   SimilarityImage = image;
   BestMatch = bestMatch;
   SimilarityMetric = similarityMetric;
 }
예제 #46
0
    public void Test_IComparable()
    {
      MagickGeometry first = new MagickGeometry(10, 5);

      Assert.AreEqual(0, first.CompareTo(first));
      Assert.AreEqual(1, first.CompareTo(null));
      Assert.IsFalse(first < null);
      Assert.IsFalse(first <= null);
      Assert.IsTrue(first > null);
      Assert.IsTrue(first >= null);
      Assert.IsTrue(null < first);
      Assert.IsTrue(null <= first);
      Assert.IsFalse(null > first);
      Assert.IsFalse(null >= first);

      MagickGeometry second = new MagickGeometry(5, 5);

      Assert.AreEqual(1, first.CompareTo(second));
      Assert.IsFalse(first < second);
      Assert.IsFalse(first <= second);
      Assert.IsTrue(first > second);
      Assert.IsTrue(first >= second);

      second = new MagickGeometry(5, 10);

      Assert.AreEqual(0, first.CompareTo(second));
      Assert.IsFalse(first == second);
      Assert.IsFalse(first < second);
      Assert.IsTrue(first <= second);
      Assert.IsFalse(first > second);
      Assert.IsTrue(first >= second);
    }
예제 #47
0
        public QuantumType[] GetArea(MagickGeometry geometry)
        {
            Throw.IfNull("geometry", geometry);

            return(GetArea(geometry.X, geometry.Y, geometry.Width, geometry.Height));
        }
예제 #48
0
        public ushort[] ToShortArray(MagickGeometry geometry, string mapping)
        {
            Throw.IfNull(nameof(geometry), geometry);

            return(ToShortArray(geometry.X, geometry.Y, geometry.Width, geometry.Height, mapping));
        }
예제 #49
0
 /// <summary>
 /// Adds a new instance of the <see cref="DrawableComposite" /> class to the <see cref="Drawables" />.
 /// </summary>
 /// <param name="offset">The offset from origin.</param>
 /// <param name="compose">The algorithm to use.</param>
 /// <param name="image">The image to draw.</param>
 /// <returns>The <see cref="Drawables" /> instance.</returns>
 public Drawables Composite(MagickGeometry offset, CompositeOperator compose, MagickImage image)
 {
     _Drawables.Add(new DrawableComposite(offset, compose, image));
     return(this);
 }
예제 #50
0
 public virtual void SetArea(MagickGeometry geometry, int[] values)
 {
     SetArea(geometry.X, geometry.Y, geometry.Width, geometry.Height, values);
 }
예제 #51
0
        public void CopyFile(string filename, string destFile)
        {
            using (MagickImage image = new MagickImage(filename))
            {
                double zw = (double)Width / image.Width;
                double zh = (double)Height /image.Height;
                double za = FillImage ? ((zw <= zh) ? zw : zh) : ((zw >= zh) ? zw : zh);

                if (FillImage)
                {
                    double aspect = (double) VideoType.Width/VideoType.Height;
                    double pAspect = (double) image.Width/image.Height;
                    if (aspect > pAspect)
                        image.Crop(image.Width, (int) (image.Width/aspect), Gravity.Center);
                    else
                        image.Crop((int) (image.Height/aspect), image.Height, Gravity.Center);
                }

                MagickGeometry geometry = new MagickGeometry(VideoType.Width, VideoType.Height)
                {
                    IgnoreAspectRatio = false,
                    FillArea = false
                };

                image.FilterType = FilterType.Point;
                image.Resize(geometry);
                image.Quality = 80;
                image.Format = MagickFormat.Jpeg;
                image.Write(destFile);
            }
        }
예제 #52
0
파일: ImgCov.cs 프로젝트: Centny/cswf.doc
 public ImgCov(String src, String dst_f, int maxw = 768, int maxh = 1024, int beg = 0) : base(src, dst_f, maxw, maxh, beg)
 {
     this.size = new MagickGeometry(maxw, maxh);
     this.size.Greater = true;
 }
예제 #53
-1
        public bool Save()
        {
            try
            {
                Database db = new Database("Database");

                string destPath = Path.Combine(ConfigurationManager.AppSettings["destinationFolder"], this.FilePath, this.FileName);
                if (!Directory.Exists(Path.GetDirectoryName(destPath))) Directory.CreateDirectory(Path.GetDirectoryName(destPath));
                // If this throws an error the archive code is not working
                fileInfo.MoveTo(destPath);
                // Read from file
                using (MagickImage image = new MagickImage(destPath))
                {
                    MagickGeometry size = new MagickGeometry(200, 200);
                    size.IgnoreAspectRatio = true;
                    image.Resize(size);
                    image.Write(destPath + "_small");
                }

                using (MagickImage image = new MagickImage(destPath))
                {
                    MagickGeometry size = new MagickGeometry(800, 800);
                    size.IgnoreAspectRatio = true;
                    image.Resize(size);
                    image.Write(destPath + "_medium");
                }

                FTP.UploadFile(this);
                db.Insert(this);

                return true;
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Could not insert {0} into the database: {1}", this.Name, ex);
                return false;
            }
        }