Esempio n. 1
0
        public void ExecuteAction(IServiceProvider serviceProvider, ref object request, ref BaseResponse response)
        {
            GetImageContentsRequest  requestMessage  = request as GetImageContentsRequest;
            GetImageContentsResponse responseMessage = response as GetImageContentsResponse;

            using (JMoviesEntities entities = new JMoviesEntities())
            {
                responseMessage.Image = entities.Image.FirstOrDefault(e => e.ID == requestMessage.ID);
            }
        }
Esempio n. 2
0
        public ActionResult Get(long id, int w, int h)
        {
            GetImageContentsRequest request = new GetImageContentsRequest {
                ID = id
            };
            GetImageContentsResponse response = jmAppClientProvider.CallAction <GetImageContentsResponse>(ActionNameConstants.GetImageContents, request);

            if (response.Image == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                if (w != default(int) || h != default(int))
                {
                    using (Image image = Image.Load(response.Image.Content))
                    {
                        if (w != default(int))
                        {
                            h = (int)((double)image.Height / (double)image.Width * (double)w);
                        }
                        else
                        {
                            w = (int)((double)image.Width / (double)image.Height * (double)h);
                        }
                        ResizeOptions resizeOptions = new ResizeOptions
                        {
                            Size = new Size
                            {
                                Width  = w,
                                Height = h
                            }
                        };

                        using (MemoryStream stream = new MemoryStream())
                        {
                            image.Mutate(e => e.Resize(resizeOptions));
                            image.Save(stream, new JpegEncoder());
                            return(new FileContentResult(stream.ToArray(), "image/jpeg"));
                        }
                    }
                }
                else
                {
                    string extension = Path.GetExtension(response.Image.URL).TrimStart('.');
                    if (extension == "jpg")
                    {
                        extension = "jpeg";
                    }
                    string mimeType = "image/" + extension;
                    return(new FileContentResult(response.Image.Content, mimeType));
                }
            }
        }