コード例 #1
0
        public static async Task <BaseImage> CreateAsync <TColor>(Image <TColor> sourceImage, string name, Effect newEffect = null, BaseImage parentImage = null, IEnumerable <Vector2> facePoints = null,
                                                                  bool isRgb = true, int?xTop = null, int?yTop = null, int?xBottom = null, int?yBottom = null)
            where TColor : struct, IPixel <TColor>
        {
            BaseImage img = new BaseImage
            {
                Name   = name,
                Width  = sourceImage.Width,
                Height = sourceImage.Height,
            };

            SetImageCommonProperties(img, newEffect, parentImage, facePoints, isRgb, (xTop, yTop, xBottom, yBottom));

            var fsPath    = img.GetFileServerPath();
            var fInfoDest = new FileInfo(fsPath);

            if (!fInfoDest.Directory.Exists)
            {
                fInfoDest.Directory.Create();
            }
            using (var writeStream = File.Create(fsPath))
            {
                sourceImage.SaveAsJpeg(writeStream, new JpegEncoder {
                    Quality = 100
                });
            }
            return(await Task.FromResult(img).ConfigureAwait(false));
        }
コード例 #2
0
 private static void SetImageCommonProperties(BaseImage image, Effect newEffect, BaseImage parentImage, IEnumerable <Vector2> facePoints, bool isRgb, (int?xTop, int?yTop, int?xBottom, int?yBottom) faceBox)
コード例 #3
0
        public static async Task <BaseImage> CreateAsync(string fileName, Effect newEffect = null, BaseImage parentImage = null, bool copyToFileServer = true, IEnumerable <Vector2> facePoints = null,
                                                         bool isRgb = true, int?xTop = null, int?yTop = null, int?xBottom = null, int?yBottom = null)
        {
            var fInfo = new FileInfo(fileName);

            BaseImage img = new BaseImage
            {
                Name = fInfo.Name,
            };

            img.GetDimensions(fileName);
            SetImageCommonProperties(img, newEffect, parentImage, facePoints, isRgb, (xTop, yTop, xBottom, yBottom));
            if (copyToFileServer)
            {
                var fsPath    = img.GetFileServerPath();
                var fInfoDest = new FileInfo(fsPath);

                if (!fInfoDest.Directory.Exists)
                {
                    fInfoDest.Directory.Create();
                }
                using (var readStream = File.OpenRead(fileName))
                    using (var writeStream = File.Create(fsPath))
                    {
                        await readStream.CopyToAsync(writeStream).ConfigureAwait(false);
                    }
            }
            return(img);
        }