WebMedia
The WebMedia class allows the developer to request a media in a format suitable for the web.
var client = ClientFactory.GetSdkClient();
var webMedia = client.Load<WebMedia>(223).FirstOrDefault();
if (webMedia != null) {
var html = string.Format("<img url=\"{0}\" width=\"{1}\" height=\"{2}\"/>", webMedia.Url, webMedia.Width,
webMedia.Height);
}
The main difference with the Media class is that you can specify a target size of the media regardless of type. An image will be a resized image, a video will also be resized (or contained in an embedded player of the requested size) and audio will be visible in a player that utilizes the requested size.
The WebMedia class extends the Media class and all properties that works for Media also works for WebMedia (see the Media section for more information)
Resize
To resize the media, use the Resize method.
var client = ClientFactory.GetSdkClient();
var webMedia = client.Load<WebMedia>(223).Resize(300, 200, ResizeMode.ScaleToFill).FirstOrDefault();
if (webMedia != null) {
var html = string.Format("<img url=\"{0}\" width=\"{1}\" height=\"{2}\"/>", webMedia.Url, webMedia.Width,
webMedia.Height);
}
The method takes three arguments:
width: The width of the resized media
height (optional): The height of the resized media
resizeMode (optional): In which way to resize the media. There are two alternatives:
ScaleToFit - Scales the media to fit inside the specified width and height, aspect ratio is kept. This is the default.
ScaleToFill - Scales the media to fill the specified width and height, aspect ratio is enforced by cropping if necessary.
Note! ScaleToFill requires both width and height to be set.
Crop
To crop the media, use the Crop method.
var client = ClientFactory.GetSdkClient();
var webMedia = client.Load<WebMedia>(223).Crop(10, 20, 50, 50).FirstOrDefault();
if (webMedia != null) {
var html = string.Format("<img url=\"{0}\" width=\"{1}\" height=\"{2}\"/>", webMedia.Url, webMedia.Width,
webMedia.Height);
}
The method takes four arguments:
X: The left coordinate where the crop starts
Y: The top coordinate where the crop starts
Width: The width of the crop area
Height: The height of the crop area