Here we draw an image and a text caption on a Canvas. We centre
horizontally text and image. The image is aligned to the top (the
default) and the caption to the bottom.
[C#]
Canvas canvas = new Canvas();
XImage image = XImage.FromFile(Server.MapPath("rez/boat.gif"));
DrawOptions drawOpts = new DrawOptions();
drawOpts.HAlign = 0.5;
drawOpts.VAlign = 0;
drawOpts.TextHAlign = 0.5;
drawOpts.TextVAlign = 1;
XText caption = canvas.GetTextMetrics("My image caption", drawOpts);
canvas.Width = image.Width + 40;
canvas.Height = image.Height + caption.LineHeight;
canvas.DrawImage(image, drawOpts);
canvas.DrawText(caption.Text, drawOpts);
canvas.SaveAs(Server.MapPath("DrawOptions_Align_83.png"));
[Visual Basic]
Dim canvas As New Canvas()
Dim image As XImage = XImage.FromFile(Server.MapPath("rez/boat.gif"))
Dim drawOpts As New DrawOptions()
drawOpts.HAlign = 0.5
drawOpts.VAlign = 0
drawOpts.TextHAlign = 0.5
drawOpts.TextVAlign = 1
Dim caption As XText = canvas.GetTextMetrics("My image caption", drawOpts)
canvas.Width = image.Width + 40
canvas.Height = image.Height + caption.LineHeight
canvas.DrawImage(image, drawOpts)
canvas.DrawText(caption.Text, drawOpts)
canvas.SaveAs(Server.MapPath("DrawOptions_Align_83.png"))
DrawOptions_Align_83.png
|