コード例 #1
0
ファイル: PhotoController.cs プロジェクト: Zeephyyr/mvccourse
        public FileContentResult GetImg(string photoName, string uniqueUserName, RequiredImgSize size)
        {
            var request = new RequestEntity
            {
                RequiredSize   = size,
                PhotoName      = photoName,
                UniqueUserName = uniqueUserName
            };

            ImageData img = _photoService.GetImgByName(request);

            return(File(img.Content, img.ImageMimeType));
        }
コード例 #2
0
ファイル: PhotoService.cs プロジェクト: Zeephyyr/mvccourse
        private byte[] CutImage(byte[] imageData, RequiredImgSize size)
        {
            Bitmap image;

            using (var ms = new MemoryStream(imageData))
            {
                image = new Bitmap(ms);
            }

            int   imageSourceWidth  = image.Width;
            int   imageSourceHeight = image.Height;
            float modifier;
            int   imageMaxWidth;
            int   imageMaxHeight;

            if (size == RequiredImgSize.Mini)
            {
                imageMaxWidth  = 400;
                imageMaxHeight = 400;
            }
            else
            {
                imageMaxWidth  = 600;
                imageMaxHeight = 800;
            }


            if (imageSourceWidth > imageSourceHeight)
            {
                modifier = (float)imageSourceWidth / imageMaxWidth;
            }
            else
            {
                modifier = (float)imageSourceHeight / imageMaxHeight;
            }
            image = ResizeImage(image, (int)(imageSourceWidth / modifier), (int)(imageSourceHeight / modifier));

            return(ImageToByte(image));
        }