当前位置: 首页>>代码示例>>C#>>正文


C# MagickImage.Resize方法代码示例

本文整理汇总了C#中ImageMagick.MagickImage.Resize方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.Resize方法的具体用法?C# MagickImage.Resize怎么用?C# MagickImage.Resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImageMagick.MagickImage的用法示例。


在下文中一共展示了MagickImage.Resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

        private static void Process(int width, int height, MagickImage image, int? quality)
        {
            image.Strip();

            if (quality.HasValue)
            {
                image.Quality = quality.Value;
            }

            //模版的宽高比例
            var templateRate = (double)width / height;

            //原图片的宽高比例
            var nowRate = (double)image.Width / image.Height;

            if (templateRate < nowRate)
            {
                //以高为准缩放
                // Resize each image in the collection to a width of 200. When zero is specified for the height
                // the height will be calculated with the aspect ratio.
                image.Resize(0, height);
                image.ChopHorizontal(width, image.Width - width);
            }
            else
            {
                //以宽为准缩放
                image.Resize(width, 0);
                image.ChopVertical(height, image.Height - height);
            }
        }
开发者ID:yongfa365,项目名称:ImageResizer,代码行数:30,代码来源:Helper.cs

示例2: Draw

        public void Draw(MagickImage map)
        {
            MainForm.ProgressStart("Drawing lightmap ...");

            // Get the heightmap
            MagickImage heightmap = zoneConfiguration.Heightmap.Heightmap;

            using (MagickImage lightmap = new MagickImage(Color.Transparent, 256, 256))
            {
                using (PixelCollection heightmapPixels = heightmap.GetReadOnlyPixels())
                {
                    using (WritablePixelCollection lightmapPixels = lightmap.GetWritablePixels())
                    {
                        // z-component of surface normals
                        double nz = 512d / zScale;
                        double nz_2 = nz * nz;
                        double nzlz = nz * lightVector[2];

                        int y1 = 0, y2 = 0;
                        for (int y = 0; y < lightmap.Height; y++)
                        {
                            if (y == 0) y1 = 0;
                            else y1 = y - 1;
                            if (y == 255) y2 = 255;
                            else y2 = y + 1;

                            int x1 = 0, x2 = 0;
                            for (int x = 0; x < lightmap.Width; x++)
                            {
                                if (x == 0) x1 = 0;
                                else x1 = x - 1;
                                if (x == 255) x2 = 255;
                                else x2 = x + 1;

                                double l = heightmapPixels.GetPixel(x1, y).GetChannel(0);
                                double r = heightmapPixels.GetPixel(x2, y).GetChannel(0);
                                double u = heightmapPixels.GetPixel(x, y1).GetChannel(0);
                                double d = heightmapPixels.GetPixel(x, y2).GetChannel(0);

                                double nx = l - r;
                                double ny = u - d;

                                double m_normal = Math.Sqrt(nx * nx + ny * ny + nz_2);
                                double ndotl = (nx * lightVector[0] + ny * lightVector[1] + nzlz) / m_normal;

                                double pixelValue = lightBase - ndotl * lightScale * 256d;

                                ushort pixelValueDiff = 0;
                                ushort alphaValue = ushort.MaxValue;
                                if(pixelValue < 0)
                                {
                                    pixelValueDiff = 0;
                                    alphaValue = (ushort)pixelValue;
                                }
                                else
                                {
                                    pixelValueDiff = (ushort)pixelValue;
                                }

                                // ColorDodge map
                                // white lightens areas where black does nothing
                                // alpha darkens areas
                                lightmapPixels.Set(x, y, new ushort[] { pixelValueDiff, pixelValueDiff, pixelValueDiff, alphaValue });
                            }

                            int percent = 100 * y / lightmap.Height;
                            MainForm.ProgressUpdate(percent);
                        }
                    }
                }

                MainForm.ProgressStartMarquee("Merging...");
                lightmap.Blur(0.0, 0.5);

                lightmap.VirtualPixelMethod = VirtualPixelMethod.Transparent;
                lightmap.FilterType = FilterType.Gaussian;
                lightmap.Resize(zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize);

                // Apply the bumpmap using ColorDodge
                map.Composite(lightmap, 0, 0, CompositeOperator.ColorDodge);

                MainForm.ProgressReset();
            }
        }
开发者ID:Merec,项目名称:DAoC-MapCreator,代码行数:84,代码来源:MapLightmap.cs

示例3: Test_Sketch

    public void Test_Sketch()
    {
      using (MagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
      {
        image.Resize(400, 400);

        image.Sketch();
        image.ColorType = ColorType.Bilevel;

        ColorAssert.AreEqual(MagickColors.White, image, 63, 100);
        ColorAssert.AreEqual(MagickColors.White, image, 150, 175);
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:13,代码来源:MagickImageTests.cs

示例4: Test_KernelProfileRecords

    public void Test_KernelProfileRecords()
    {
      OpenCLDevice device = GetEnabledDevice();
      if (device == null)
        Assert.Inconclusive("No OpenCL devices detected.");

      device.ProfileKernels = true;

      using (MagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
      {
        image.Resize(500, 500);
        image.Resize(100, 100);
      }

      device.ProfileKernels = false;

      List<OpenCLKernelProfileRecord> records = new List<OpenCLKernelProfileRecord>(device.KernelProfileRecords);
      Assert.IsFalse(records.Count < 2);

      foreach (OpenCLKernelProfileRecord record in records)
      {
        Assert.IsNotNull(record.Name);
        Assert.IsFalse(record.Count < 0);
        Assert.IsFalse(record.MaximumDuration < 0);
        Assert.IsFalse(record.MinimumDuration < 0);
        Assert.IsFalse(record.TotalDuration < 0);

        Assert.AreEqual(record.AverageDuration, record.TotalDuration / record.Count);
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:30,代码来源:OpenCLDeviceTests.cs

示例5: FastBlur

        public static Bitmap FastBlur(Uri image, double percentage)
        {
            MagickImage magick = new MagickImage(new Bitmap(image.AbsolutePath));
            magick.Resize(new Percentage(50.0 / percentage));
            magick.Resize(new Percentage(200 * percentage));

            return magick.ToBitmap();
        }
开发者ID:Tragedian-HLife,项目名称:HLife,代码行数:8,代码来源:ImageUtilities.cs

示例6: Exec

 public override void Exec()
 {
     try
     {
         var img = new ImageMagick.MagickImage(this.AsSrc);
         img.BackgroundColor = new MagickColor(Color.White);
         if (".jpg".Equals(Path.GetExtension(this.DstF), StringComparison.OrdinalIgnoreCase))
         {
             img.HasAlpha = false;
         }
         img.Resize(this.size);
         var as_dst = String.Format(this.AsDstF, this.Beg);
         var as_dir = Path.GetDirectoryName(as_dst);
         if (!Directory.Exists(as_dir))
         {
             Directory.CreateDirectory(as_dir);
         }
         img.Write(as_dst);
         this.Result.Files.Add(String.Format(this.DstF, this.Beg));
         this.Result.Count += 1;
     }
     catch (Exception e)
     {
         this.Result.Code = 500;
         this.Fails.Add(e);
     }
 }
开发者ID:Centny,项目名称:cswf.doc,代码行数:27,代码来源:ImgCov.cs

示例7: ResizePng

 public void ResizePng(PngFileInfo sourcePngFile, PngFileInfo targetPngFile)
 {
     _logger.InfoFormat("Resizing: {0} -> {1}", sourcePngFile.Name, targetPngFile.Name);
     var sourcePngFileInfo = new FileInfo(sourcePngFile.FullName);
     using (var sourceImage = new MagickImage(sourcePngFileInfo))
     {
         sourceImage.Resize(targetPngFile.Size, targetPngFile.Size);
         var targetPngFileInfo = new FileInfo(targetPngFile.FullName);
         sourceImage.Write(targetPngFileInfo);
     }
 }
开发者ID:trondr,项目名称:NMultiTool,代码行数:11,代码来源:ImageMagicProvider.cs

示例8: Execute

        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;
        }
开发者ID:CadeLaRen,项目名称:digiCamControl,代码行数:15,代码来源:ResizeTransform.cs

示例9: ResizeToFixedSize

    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");
      }
    }
开发者ID:levesque,项目名称:Magick.NET,代码行数:16,代码来源:ResizeImage.cs

示例10: Execute

        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new PixelBinningViewModel(configData);
            dest = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest) + ".jpg");

            using (MagickImage image = new MagickImage(infile))
            {
                int newx = image.Width/(conf.SelectedMode + 2);
                int newy = image.Height / (conf.SelectedMode + 2);
                int cropx = newx * (conf.SelectedMode + 2);
                int cropy = newy * (conf.SelectedMode + 2);
                if (cropx != image.Width || cropy != image.Height)
                    image.Crop(cropx, cropy, Gravity.Center);
                image.FilterType = FilterType.Box;
                image.Resize(newx,newy);
                image.Format = MagickFormat.Jpeg;
                image.Write(dest);
            }
            return dest;
        }
开发者ID:CadeLaRen,项目名称:digiCamControl,代码行数:20,代码来源:PixelBinning.cs

示例11: ResizeImageByLengthOfLongestSide

        public Uri ResizeImageByLengthOfLongestSide(Uri imageToResizeUri)
        {
            var fileName = Path.GetFileName(imageToResizeUri.LocalPath);

            var magicImage = new MagickImage(Path.Combine(_fileStorageSettings.ImageStorageFolder, fileName));

            var size = magicImage.Height >= magicImage.Width
                ? new MagickGeometry(_lengthOfLongestSideOfResized, 0)
                : new MagickGeometry(0, _lengthOfLongestSideOfResized);

            size.IgnoreAspectRatio = false;

            magicImage.Resize(size);

            var newName = GenerateRandomFileName(magicImage.FileName);
            var pathOfNewImage = Path.Combine(_fileStorageSettings.ImageStorageFolder, newName);
            magicImage.Write(pathOfNewImage);

            return new Uri($"{_applicationLocationSettings.BackendAdress}/image/" + newName);
        }
开发者ID:LeagueOfDevelopers,项目名称:LodCore,代码行数:20,代码来源:ImageResizer.cs

示例12: Test_Unregister

    public void Test_Unregister()
    {
      using (MagickImage image = new MagickImage(Files.SnakewarePNG))
      {
        using (MemoryStream memoryStream = new MemoryStream())
        {
          image.Resize(256, 256);
          image.Format = MagickFormat.Ico;
          image.Write(memoryStream);
          memoryStream.Position = 0;

          MagickFormatInfo formatInfo = MagickNET.GetFormatInformation(MagickFormat.Ico);
          Assert.IsNotNull(formatInfo);
          Assert.IsTrue(formatInfo.Unregister());

          ExceptionAssert.Throws<MagickMissingDelegateErrorException>(delegate ()
          {
            new MagickImage(memoryStream);
          });
        }
      }
    }
开发者ID:levesque,项目名称:Magick.NET,代码行数:22,代码来源:MagickFormatInfoTests.cs

示例13: CopyFile

        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);
            }
        }
开发者ID:CadeLaRen,项目名称:digiCamControl,代码行数:31,代码来源:GenMovieViewModel.cs

示例14: ApplyPreviewImageMagick

        public static void ApplyPreviewImageMagick(string source, string destination, double maxWidth = 0d, double maxHeight = 0d) {
            using (var image = new MagickImage(source)) {
                if (maxWidth > 0d || maxHeight > 0d) {
                    var k = Math.Max(maxHeight / image.Height, maxWidth / image.Width);
                    image.Interpolate = PixelInterpolateMethod.Bicubic;
                    image.FilterType = FilterType.Lanczos;
                    image.Sharpen();
                    image.Resize((int)(k * image.Width), (int)(k * image.Height));
                    image.Crop(CommonAcConsts.PreviewWidth, CommonAcConsts.PreviewHeight, Gravity.Center);
                }

                image.Quality = 95;
                image.Density = new MagickGeometry(96, 96);
                if (File.Exists(destination)) {
                    try {
                        File.Delete(destination);
                    } catch (UnauthorizedAccessException) {
                        Thread.Sleep(200);
                        File.Delete(destination);
                    }
                }

                image.Write(destination);
            }
        }
开发者ID:gro-ove,项目名称:actools,代码行数:25,代码来源:ImageUtils.cs

示例15: PointGenerator

        public static List<string> PointGenerator(string inputBitmapPath, PixFormat _pixFor)
        {
            List<string> imglist = new List<string>();
            try
            {
                if (_pixFor == PixFormat._null)
                    throw new Exception("Format null olamaz") { Source = "" };

                using (MagickImage imagem = new MagickImage(inputBitmapPath))
                {
                    //############# ResizeImage #############
                    int yuzde = 100;
                    imagem.Quality = 100;
                    int _w = imagem.Width + (imagem.Width / 100) * yuzde;
                    int _h = imagem.Height + (imagem.Height / 100) * yuzde;
                    int new_W = _w - (_w % (int)_pixFor);
                    int new_H = _h - (_h % (int)_pixFor);
                    imagem.Resize(new_W, new_H);
                    imagem.Blur(5, 5);
                    //############# GenerateSquare #############
                    /////////// calculate image point rgb avg   ////////////
                    string curImgPth = Path.GetFileName(inputBitmapPath);
                    string path = UserProperty.PixelXmlMap_Path + "\\" + curImgPth.Substring(0, curImgPth.Length - 4) + _pixFor.ToString() + "_.xml";
                    FileInfo finf = new FileInfo(path);
                    List<ImgSquare> sp0 = new List<ImgSquare>();
                    if (!File.Exists(path))
                    {
                        int[,] pixavg = new int[5, 3];
                        int _pixformat = (int)_pixFor;
                        WritablePixelCollection _totalpix = imagem.GetWritablePixels(0, 0, imagem.Width, imagem.Height);
                        int range = _pixformat / 2;
                        for (int w = 0; w < imagem.Width; w += _pixformat)
                        {
                            for (int h = 0; h < imagem.Height; h += _pixformat)
                            {
                                if (!(w + _pixformat <= imagem.Width && h + _pixformat <= imagem.Height))
                                    continue;//olmazda olursa diye
                                pixavg = new int[5, 3];
                                for (int x = 0; x < range; x++)
                                {
                                    for (int y = 0; y < range; y++)
                                    {
                                        Color a = _totalpix.GetPixel(x + w + 0, h + 0 + y).ToColor().ToColor();
                                        pixavg[0, 0] += a.R;
                                        pixavg[0, 1] += a.G;
                                        pixavg[0, 2] += a.B;

                                        Color b = _totalpix.GetPixel(x + w + range, h + y).ToColor().ToColor();
                                        pixavg[1, 0] += b.R;
                                        pixavg[1, 1] += b.G;
                                        pixavg[1, 2] += b.B;

                                        Color c = _totalpix.GetPixel(x + w, h + range + y).ToColor().ToColor();
                                        pixavg[2, 0] += c.R;
                                        pixavg[2, 1] += c.G;
                                        pixavg[2, 2] += c.B;

                                        Color d = _totalpix.GetPixel(x + w + range, h + range + y).ToColor().ToColor();
                                        pixavg[3, 0] += d.R;
                                        pixavg[3, 1] += d.G;
                                        pixavg[3, 2] += d.B;
                                    }
                                }

                                //tümü için aynı toplanıyor
                                pixavg[4, 0] = pixavg[0, 0] + pixavg[1, 0] + pixavg[2, 0] + pixavg[3, 0];
                                pixavg[4, 1] = pixavg[0, 1] + pixavg[1, 1] + pixavg[2, 1] + pixavg[3, 1];
                                pixavg[4, 2] = pixavg[0, 2] + pixavg[1, 2] + pixavg[2, 2] + pixavg[3, 2];
                                //----

                                int totalminiPix = (range * range);
                                pixavg[0, 0] /= totalminiPix;
                                pixavg[0, 1] /= totalminiPix;
                                pixavg[0, 2] /= totalminiPix;

                                pixavg[1, 0] /= totalminiPix;
                                pixavg[1, 1] /= totalminiPix;
                                pixavg[1, 2] /= totalminiPix;

                                pixavg[2, 0] /= totalminiPix;
                                pixavg[2, 1] /= totalminiPix;
                                pixavg[2, 2] /= totalminiPix;

                                pixavg[3, 0] /= totalminiPix;
                                pixavg[3, 1] /= totalminiPix;
                                pixavg[3, 2] /= totalminiPix;


                                int totalPix = totalminiPix * 4;
                                pixavg[4, 0] /= totalPix;
                                pixavg[4, 1] /= totalPix;
                                pixavg[4, 2] /= totalPix;

                                sp0.Add(new ImgSquare(w, h, new List<QuardPixAvg>() 
                            {
                                new QuardPixAvg(Color.FromArgb((pixavg[0, 0]), (pixavg[0, 1]), (pixavg[0, 2])), QuardBolum.SolUst),
                                new QuardPixAvg (Color.FromArgb((pixavg[1, 0]), (pixavg[1, 1]), (pixavg[1, 2])), QuardBolum.SagUst),
                                new QuardPixAvg(Color.FromArgb((pixavg[2, 0]), (pixavg[2, 1]), (pixavg[2, 2])), QuardBolum.SolAlt),
                                new QuardPixAvg(Color.FromArgb((pixavg[3, 0]), (pixavg[3, 1]), (pixavg[3, 2])), QuardBolum.SagAlt),
                                new QuardPixAvg(Color.FromArgb((pixavg[4, 0]), (pixavg[4, 1]), (pixavg[4, 2])), QuardBolum.TotalAvg)
//.........这里部分代码省略.........
开发者ID:msx752,项目名称:OPALOP-Picture-Mosaic,代码行数:101,代码来源:ImageProperty.cs


注:本文中的ImageMagick.MagickImage.Resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。