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


C# MagickImage.ToByteArray方法代码示例

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


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

示例1: Execute

        public async Task<ValidationResult> Execute(MediaInfo mediaInfo, Int32 x, Int32 y, Int32 width, Int32 height)
        {
            if (x < 0 || y < 0 || width <= 0 || height <= 0)
            {
                return new ValidationResult("サイズの指定が不正です。");
            }

            var mediaContent = await _mediaRepository.Get(mediaInfo);
            if (mediaContent == null)
            {
                return new ValidationResult("指定されたメディアが見つかりませんでした。");
            }

            var data = await mediaContent.GetContentAsync();
            var imageInfo = new MagickImageInfo(data);
            if (imageInfo.Width < (x + width) || imageInfo.Height < (y + height))
            {
                return new ValidationResult("指定されたサイズは画像のサイズを超えています。");
            }

            // リサイズするよ!
            using (var image = new MagickImage(data))
            {
                image.Crop(new MagickGeometry(x, y, width, height));
                image.Page = new MagickGeometry(0, 0, width, height);
                
                // そして更新
                await _mediaRepository.Update(mediaInfo, image.ToByteArray());
            }

            return ValidationResult.Success;
        }
开发者ID:gogosub77,项目名称:Kanae,代码行数:32,代码来源:Crop.cs

示例2: ConvertImageFromOneFormatToAnother

    public static void ConvertImageFromOneFormatToAnother()
    {
      // Read first frame of gif image
      using (MagickImage image = new MagickImage(SampleFiles.SnakewareGif))
      {
        // Save frame as jpg
        image.Write(SampleFiles.OutputDirectory + "Snakeware.jpg");
      }

      MagickReadSettings settings = new MagickReadSettings();
      // Tells the xc: reader the image to create should be 800x600
      settings.Width = 800;
      settings.Height = 600;

      using (MemoryStream memStream = new MemoryStream())
      {
        // Create image that is completely purple and 800x600
        using (MagickImage image = new MagickImage("xc:purple", settings))
        {
          // Sets the output format to png
          image.Format = MagickFormat.Png;
          // Write the image to the memorystream
          image.Write(memStream);
        }
      }

      // Read image from file
      using (MagickImage image = new MagickImage(SampleFiles.SnakewarePng))
      {
        // Sets the output format to jpeg
        image.Format = MagickFormat.Jpeg;
        // Create byte array that contains a jpeg file
        byte[] data = image.ToByteArray();
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:35,代码来源:ConvertImage.cs

示例3: LoadFromFileAsConventionalBuffer

 public static byte[] LoadFromFileAsConventionalBuffer(string filename, bool wrapping = true) {
     if (wrapping && SafeMagickWrapper != null) {
         return SafeMagickWrapper(() => LoadFromFileAsConventionalBuffer(filename, false)) as byte[];
     }
     
     using (var image = new MagickImage(filename)) {
         return image.ToByteArray(CommonFormat);
     }
 }
开发者ID:gro-ove,项目名称:actools,代码行数:9,代码来源:ImageUtils.cs

示例4: FromPDF

        public static Png FromPDF(string file)
        {
            if (!File.Exists(file))
                throw new FileNotFoundException($"Could not find PDF file {file}");

            using (var page = new MagickImage(file))
            {
                var data = page.ToByteArray(MagickFormat.Png);
                return new Png(data, page.Height, page.Width);
            }
        }
开发者ID:masaeedu,项目名称:files2textures,代码行数:11,代码来源:Convert.cs

示例5: ImageProcessing

        // Load images from twitter, process them into collage
        string ImageProcessing(List<string> urls, int size, List<int> counts, bool resize)
        {
            byte[] imageByteData = null;
            byte[] data = null;
            // Load images into collection
            using (MagickImageCollection collection = new MagickImageCollection())
            {
                
                for (int i = 0; i < urls.Count; i++)
                {
                    imageByteData = new System.Net.WebClient().DownloadData(urls[i]);
                    MagickImage tmpImage = new MagickImage(imageByteData);
                    collection.Add(tmpImage);
                }
                // generade byte array for collage from images collection
                if (resize)
                {
                    // collage with proportional images
                    SizableImages simages = new SizableImages(counts);
                    List<SizableImage> arrangedImages = simages.GetImages();
                    int width = simages.GetXBottom() - simages.GetXTop();
                    int height = simages.GetYBottom() - simages.GetYTop();

                    int maxDimension;

                    if (width < height)
                    {
                        maxDimension = height;
                    }
                    else
                    {
                        maxDimension = width;
                    }

                    double correction = (double)size / maxDimension;


                    MagickReadSettings settings = new MagickReadSettings();
                    settings.Width = (int)(width * correction);
                    settings.Height = (int)(height * correction);
                    using (MagickImage image = new MagickImage("xc:white", settings))
                    {
                        for (int i = 0; i < arrangedImages.Count(); i++)
                        {
                            collection[
                                arrangedImages[i].id
                                ].Resize(new MagickGeometry((int)(arrangedImages[i].size * correction)));
                            image.Composite(collection[arrangedImages[i].id],
                                (int)(arrangedImages[i].positionX * correction),
                                (int)(arrangedImages[i].positionY * correction));
                        }
                        image.Format = MagickFormat.Png;
                        data = image.ToByteArray();
                    }
                }
                else
                {
                    // collage with single sized images
                    data = GenerateCollage(collection, size);
                }
            }
            // convert byte array to data url
            string imageBase64Data = Convert.ToBase64String(data/*imageByteData*/);
            string imageDataURL = string.Format("data:image/png;base64,{0}", imageBase64Data);
            return imageDataURL;
        }
开发者ID:litoshko,项目名称:Twitter-Collage,代码行数:67,代码来源:HomeController.cs

示例6: SaveAndDispose

        private Task SaveAndDispose(string filename, MagickImage image) {
            try {
                if (File.Exists(filename)) {
                    FileUtils.Recycle(filename);
                }

                image.SetDefine(MagickFormat.Dds, "compression", "none");
                image.Quality = 100;
                var bytes = image.ToByteArray(MagickFormat.Dds);
                return FileUtils.WriteAllBytesAsync(filename, bytes);
            } finally {
                image.Dispose();
            }
        }
开发者ID:gro-ove,项目名称:actools,代码行数:14,代码来源:ToolsKn5ObjectRenderer.cs

示例7: OverrideTextureMaps

        public bool OverrideTextureMaps(string textureName, double reflection, double blur, double specular) {
            using (var image = new MagickImage(Kn5.TexturesData[textureName])) {
                if (image.Width > 512 || image.Height > 512) {
                    image.Resize(512, 512);
                }

                image.BrightnessContrast(reflection, 1d, Channels.Red);
                image.BrightnessContrast(blur, 1d, Channels.Green);
                image.BrightnessContrast(specular, 1d, Channels.Blue);

                return OverrideTexture(textureName, image.ToByteArray(MagickFormat.Bmp));
            }
        }
开发者ID:gro-ove,项目名称:actools,代码行数:13,代码来源:ToolsKn5ObjectRenderer.cs

示例8: OverrideTexture

 public bool OverrideTexture(string textureName, Color color, double alpha) {
     using (var image = new MagickImage(new MagickColor(color) { A = (ushort)(ushort.MaxValue * alpha) }, 4, 4)) {
         return OverrideTexture(textureName, image.ToByteArray(MagickFormat.Bmp));
     }
 }
开发者ID:gro-ove,项目名称:actools,代码行数:5,代码来源:ToolsKn5ObjectRenderer.cs

示例9: LoadAsConventionalBuffer

        public static byte[] LoadAsConventionalBuffer(byte[] data, bool noAlpha, out string formatDescription, bool wrapping = true) {
            if (wrapping && SafeMagickWrapper != null) {
                string description = null;
                var result = SafeMagickWrapper(() => LoadAsConventionalBuffer(data, noAlpha, out description, false)) as byte[];
                formatDescription = description;
                return result;
            }
            
            using (var image = new MagickImage(data)) {
                formatDescription = image.CompressionMethod.ToString();

                if (noAlpha) {
                    image.HasAlpha = false;
                }

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

示例10: Test_ToByteArray

    public void Test_ToByteArray()
    {
      using (MagickImage image = new MagickImage(Files.SnakewarePNG))
      {
        byte[] bytes = image.ToByteArray(new DdsWriteDefines()
        {
          Compression = DdsCompression.Dxt5
        });

        image.Read(bytes);
        Assert.AreEqual(CompressionMethod.DXT5, image.CompressionMethod);
        Assert.AreEqual(MagickFormat.Dds, image.Format);

        bytes = image.ToByteArray(MagickFormat.Jpg);

        image.Read(bytes);
        Assert.AreEqual(MagickFormat.Jpeg, image.Format);

        bytes = image.ToByteArray(new DdsWriteDefines()
        {
          Compression = DdsCompression.Dxt5
        });

        image.Read(bytes);
        Assert.AreEqual(CompressionMethod.DXT1, image.CompressionMethod);
        Assert.AreEqual(MagickFormat.Dds, image.Format);
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:28,代码来源:MagickImageTests.cs

示例11: SaveUploadedFile

        public ActionResult SaveUploadedFile()
        {
            bool isSavedSuccessfully = true;
            try
            {
                List<FileDto> FileList = new List<FileDto>();
                if (Session["FileList"] != null)
                {
                    FileList = Session["FileList"] as List<FileDto>;
                }
                foreach (string fileName in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[fileName];
                    MemoryStream target = new MemoryStream();
                    file.InputStream.CopyTo(target);
                    byte[] data = target.ToArray();
                    try
                    {

                        using (MagickImage image = new MagickImage())
                        {
                            image.Read(target);
                            image.Resize(800, 0);
                            data = image.ToByteArray();
                        }
                    }
                    catch
                    {

                    }

                    var str = Convert.ToBase64String(data);
                    FileDto FileUpload = new FileDto()
                    {
                        ContentType = System.IO.Path.GetExtension(file.FileName),
                        Content = str
                    };
                    //Byte[] docbinaryarray = Convert.FromBase64String(FileUpload.Content);
                    //string strdocPath = "C:\\DocumentDirectory2\\" + file.FileName + FileUpload.ContentType;
                    //FileStream objfilestream = new FileStream(strdocPath, FileMode.Create, FileAccess.ReadWrite);
                    //objfilestream.Write(docbinaryarray, 0, docbinaryarray.Length);
                    //objfilestream.Close();
                    FileList.Add(FileUpload);
                }
                Session["FileList"] = FileList;

            }
            catch (Exception ex)
            {
                isSavedSuccessfully = false;
            }


            if (isSavedSuccessfully)
            {
                return Json(new { Message = "فایل با موفقیت آپلود شد" });
            }
            else
            {
                return Json(new { Message = "خطا در آپلود فایل" });
            }
        }
开发者ID:ehsmohammadi,项目名称:BTE.RMS,代码行数:62,代码来源:MeetingsController.cs


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