Пример #1
0
        public static SaveImageModel PrepareSaveImage(string imgPath)
        {
            SaveImageModel saveImage = null;

            try
            {
                if (string.IsNullOrEmpty(imgPath))
                {
                    return(null);
                }

                if (File.Exists(imgPath))
                {
                    saveImage = new SaveImageModel();

                    saveImage.OriginalImageBytes = File.ReadAllBytes(imgPath);
                    saveImage.OriginalImage      = Image.FromFile(imgPath);

                    if (saveImage.OriginalImage.Width > ConfigurationSettings.RESIZED_IMAGE_WIDTH)
                    {
                        MemoryStream ms = new MemoryStream();

                        saveImage.ResizedImage = ResizeImage(saveImage.OriginalImage, new Size(ConfigurationSettings.RESIZED_IMAGE_WIDTH,
                                                                                               ConfigurationSettings.RESIZED_IMAGE_HEIGHT));
                        saveImage.ResizedImage.Save(ms, saveImage.OriginalImage.RawFormat);
                        saveImage.ResizedImageBytes = ms.ToArray();

                        if (saveImage.ResizedImage.Width > ConfigurationSettings.CROPPED_IMAGE_WIDTH &&
                            saveImage.ResizedImage.Height > ConfigurationSettings.CROPPED_IMAGE_HEIGHT)
                        {
                            int croppedXPosition = (saveImage.ResizedImage.Width - ConfigurationSettings.CROPPED_IMAGE_WIDTH) / 2;
                            int croppedYPosition = (saveImage.ResizedImage.Height - ConfigurationSettings.CROPPED_IMAGE_HEIGHT) / 2;

                            saveImage.CroppedImage = CropImage(saveImage.ResizedImage, new Rectangle(croppedXPosition, croppedYPosition,
                                                                                                     ConfigurationSettings.CROPPED_IMAGE_WIDTH,
                                                                                                     ConfigurationSettings.CROPPED_IMAGE_HEIGHT));
                            saveImage.CroppedImage.Save(ms, saveImage.OriginalImage.RawFormat);
                            saveImage.CroppedImageBytes = ms.ToArray();
                        }
                        else
                        {
                            MessageBox.Show(Messages.picture_war + " " + ConfigurationSettings.RESIZED_IMAGE_WIDTH + "x" + ConfigurationSettings.RESIZED_IMAGE_HEIGHT + ".",
                                            Messages.msg_war, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            saveImage = null;
                        }
                    }
                }
                else
                {
                    MessageBox.Show(Messages.picture_not_exist, Messages.msg_war, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    saveImage = null;
                }
            }
            catch
            {
                saveImage = null;
            }

            return(saveImage);
        }
Пример #2
0
        private static SaveImageModel MapImageModel(GetImageResponse response)
        {
            var model = new SaveImageModel
            {
                Version               = response.Data.Version,
                Title                 = response.Data.Title,
                Description           = response.Data.Description,
                Caption               = response.Data.Caption,
                FileSize              = response.Data.FileSize,
                ImageUrl              = response.Data.ImageUrl,
                Width                 = response.Data.Width,
                Height                = response.Data.Height,
                ThumbnailUrl          = response.Data.ThumbnailUrl,
                ThumbnailWidth        = response.Data.ThumbnailWidth,
                ThumbnailHeight       = response.Data.ThumbnailHeight,
                ThumbnailSize         = response.Data.ThumbnailSize,
                IsArchived            = response.Data.IsArchived,
                FolderId              = response.Data.FolderId,
                PublishedOn           = response.Data.PublishedOn,
                OriginalFileName      = response.Data.OriginalFileName,
                OriginalFileExtension = response.Data.OriginalFileExtension,
                OriginalWidth         = response.Data.OriginalWidth,
                OriginalHeight        = response.Data.OriginalHeight,
                OriginalSize          = response.Data.OriginalSize,
                OriginalUrl           = response.Data.OriginalUrl,
                FileUri               = response.Data.FileUri,
                IsUploaded            = response.Data.IsUploaded,
                IsTemporary           = response.Data.IsTemporary,
                IsCanceled            = response.Data.IsCanceled,
                OriginalUri           = response.Data.OriginalUri,
                ThumbnailUri          = response.Data.ThumbnailUri,
                Tags = response.Tags != null?response.Tags.Select(t => t.Name).ToList() : null,
                           Categories = response.Data.Categories != null?response.Data.Categories.Select(t => t.Id).ToList() : null,
            };

            return(model);
        }