Пример #1
0
        public byte[] processImage(byte[] byteArray, CutSetting cutSetting, SizeSetting sizeSetting, ProcessOptions processOption)
        {
            byte[] result = null;

            using (MemoryStream ms = new MemoryStream(byteArray))
            {
                Image image = Image.FromStream(ms);

                if (processOption == ProcessOptions.ResizeFirst)
                {
                    if (sizeSetting != null && sizeSetting.FrameSize.Width > 0 && sizeSetting.FrameSize.Height > 0)
                    {
                        image = ImageProcessor.ResizeImage(image, sizeSetting.FrameSize, sizeSetting.Option);
                    }
                }

                if (cutSetting != null && cutSetting.RegionSize.Width > 0 && cutSetting.RegionSize.Height > 0)
                {
                    if (cutSetting.Position == PositionOptions.Custom)
                    {
                        Point point = cutSetting.LeftTopPosition;
                        double rate = 1.0;
                        if (point == null) point = new Point(0, 0);
                        if (cutSetting.PreviewRate != null) rate = cutSetting.PreviewRate.Value;
                        image = ImageProcessor.CutImage(image, new Rectangle(point, cutSetting.RegionSize), rate);
                    }
                    else
                    {
                        string positionOption = cutSetting.Position.ToString();
                        HorizonOptions horizonOption = HorizonOptions.Left;
                        VerticalOptions verticalOption = VerticalOptions.Top;

                        if (positionOption.Contains("Left")) horizonOption = HorizonOptions.Left;
                        else if (positionOption.Contains("Center")) horizonOption = HorizonOptions.Center;
                        else if (positionOption.Contains("Right")) horizonOption = HorizonOptions.Right;

                        if (positionOption.Contains("Top")) verticalOption = VerticalOptions.Top;
                        else if (positionOption.Contains("Middle")) verticalOption = VerticalOptions.Middle;
                        else if (positionOption.Contains("Bottom")) verticalOption = VerticalOptions.Bottom;

                        image = ImageProcessor.CutImage(image, cutSetting.RegionSize, horizonOption, verticalOption);
                    }
                }

                if (processOption == ProcessOptions.CutFirst)
                {
                    if (sizeSetting != null && sizeSetting.FrameSize.Width > 0 && sizeSetting.FrameSize.Height > 0)
                    {
                        image = ImageProcessor.ResizeImage(image, sizeSetting.FrameSize, sizeSetting.Option);
                    }
                }

                ImageConverter converter = new ImageConverter();
                result = (byte[])converter.ConvertTo(image, typeof(byte[]));
            }

            return result;
        }
Пример #2
0
 public string UploadImageByUrl(string url, CutSetting cutSetting, SizeSetting sizeSetting, ProcessOptions processOption)
 {
     byte[] image;
     using (WebClient client = new WebClient())
     {
         image = client.DownloadData(Server.UrlDecode(url));
     }
     return saveImage(processImage(image, cutSetting, sizeSetting, processOption)).ToString();
 }
Пример #3
0
 public string UploadFile(byte[] image, CutSetting cutSetting, SizeSetting sizeSetting, ProcessOptions processOption)
 {
     return saveImage(processImage(image, cutSetting, sizeSetting, processOption)).ToString();
 }