Ejemplo n.º 1
0
            public static ImageInfo New(
                MediaPart mediaPart,
                ImagePart imagePart,
                int width,
                int height)
            {
                if (mediaPart == null)
                {
                    mediaPart = imagePart.As <MediaPart>();
                }
                else if (imagePart == null)
                {
                    imagePart = mediaPart.As <ImagePart>();
                }

                // at minimum, we need a MediaPart to get to a file
                if (mediaPart == null)
                {
                    return(null);
                }

                if (imagePart != null)
                {
                    // Manage Width <= 0, Height <= 0
                    if (width <= 0)
                    {
                        width = imagePart.Width;
                    }
                    if (height <= 0)
                    {
                        height = imagePart.Height;
                    }
                }

                var imagePath = mediaPart.MediaUrl;

                var img = New(imagePath, width, height);

                if (img != null)
                {
                    img.ContentItem = mediaPart.ContentItem;
                }
                return(img);
            }