Example #1
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)
Example #2
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));
        }