Images
Images from files, bytes or URLs, with crop sizing, rounding, rotation and inner/outer shadows.
DemoImage
Source file Modules/DemoImage.cs
Slide methods genSlide01 – genSlide05
Output files image_genSlide*.pptx
1Overview
DemoImage is organised as a grid of labelled cells — each caption names the option under test (e.g. "Type: GIF", "Shadow: type:inner") and a reference rectangle shows the target bounds.
Images come from Constants.IMAGE_PATHS (file registry) or from raw bytes via the data property; genSlide01 also takes an addSvg flag so the same deck can include or skip SVG sources.
2Demo methods
| Method | What it demonstrates |
|---|---|
| genSlide01(addSvg) | Image types — animated GIF, JPG/PNG and optional SVG; objectName. |
| genSlide02 | Image URLs — addImage from http(s) sources. |
| genSlide03 | Sizing & rounding — ImageSizingProps crop, rounding true/false. |
| genSlide04 | Rotation — rotate 45 / 180 / 315 degrees. |
| genSlide05 | Shadows — ShadowProps none / inner / outer with opacity, blur, offset, angle. |
3Code samples
Animated GIF and friends addImage with path + objectName; legacy PPT animation note. DemoImage.cs · genSlide01
fill = (Constants.BKGD_LTGRAY),
fontSize = 12,
fontFace = "Segoe UI",
color = Constants.COLOR_BLUE,
valign = VAlign.top,
align = HAlign.center,
});
slide.addImage(new ImageProps { x = 1.13, y = 1.1, w = 1.5, h = 1.5, path = Constants.IMAGE_PATHS.gifAnimTrippy.path, objectName = "animated gif" });
slide.addText("(legacy PPT only animates in slide show)", new TextPropsOptions
{
x = 0.5,
y = 2.79,
w = 2.75,
h = 0.3,
align = HAlign.center,
fontSize = 10,
color = "BF9000",
fill = "FFFCCC",
});
// TOP = 2
slide.addText("Type: GIF", new TextPropsOptions
{
Crop sizing & rounding ImageSizingProps(ImageSizingType.crop, w, h, x, y) and rounding:true/false. DemoImage.cs · genSlide03
slide.addText("Sizing: `crop, w:3, h:2`", new TextPropsOptions { x = 10.0, y = 4.25, w = 3.0, h = 0.3, color = Constants.COLOR_BLUE });
slide.addShape(ShapeType.rect, new ShapeProps { x = 10, y = 4.65, w = 3, h = 1.5, fill = (Constants.BKGD_LRGRAY) });
slide.addImage(new ImageProps
{
data = Constants.KRITA_SPLASHSCREEN, x = 10.0, y = 4.65, w = 5.0, h = 1.5,
sizing = new ImageSizingProps(ImageSizingType.crop, 3, 1.5, 0.5, 0.5)
});
// TOP-RIGHT =
slide.addText("Rounding: `rounding:true`", new TextPropsOptions { x = 7, y = 0.6, w = 3.0, h = 0.3, color = Constants.COLOR_BLUE });
slide.addShape(ShapeType.rect, new ShapeProps { x = 7, y = 1.0, w = 6.0, h = 3.0, fill = (BKGD_LRGRAY) });
slide.addImage(new ImageProps { path = IMAGE_PATHS.kritaSquare.path, x = 7.42, y = 1.28, w = 2.5, h = 2.5, rounding = false });
slide.addImage(new ImageProps { path = IMAGE_PATHS.kritaSquare.path, x = 10.25, y = 1.28, w = 2.5, h = 2.5, rounding = true });
Rotation rotate:45 / 180 / 315 on the same image. DemoImage.cs · genSlide04
slide.addImage(new ImageProps { path= IMAGE_PATHS.nycSubway.path, x= 0.78, y= 2.46, w= 4.5, h= 3, rotate= 45 });
slide.addImage(new ImageProps { path = IMAGE_PATHS.nycSubway.path, x= 4.42, y= 2.25, w= 4.5, h= 3, rotate= 180 });
slide.addImage(new ImageProps { path = IMAGE_PATHS.nycSubway.path, x= 8.25, y= 2.84, w= 4.5, h= 3, rotate= 315 });
Shadows ShadowProps type inner / outer with opacity, blur, offset, angle. DemoImage.cs · genSlide05
new ImageProps { path = Constants.IMAGE_PATHS.nycSubway.path, x = 7.0, y = 0.6, h = 1.4, w = 2.11 },
shadow1);
slide.addImage(imageProp);
// type = inner
ImageProps shadow2 = new ImageProps { shadow = new ShadowProps { type = ShadowType.inner, opacity = 0.5, blur = 20, color = "000000", offset = 20, angle = 320 } };
var textOption2_1 = Constants.MergeTextOption(new TextPropsOptions { x = 0.5, y = 2.45, h = 0.4, w = 6.0 }, Constants.TITLE_STYLE);
slide.addText("Shadow: `type:inner`", textOption2_1);
var textOption2_2 = Constants.MergeTextOption(Constants.BASE_CODE_OPTS,
new TextPropsOptions { x = 0.5, y = 2.85, h = 1.7, w = 6 },
Constants.CODE_STYLE);
var text2_json = Constants.ToJson(shadow2); // 对对象的序列化后和 JS 不同;
text2_json = Constants.ToJson(new { shadow = new { type = "inner", opacity = 0.5, blur = 20, color = "000000", offset = 20, angle = 320 } });
Console.WriteLine(text2_json);
slide.addText(new List<TextProps> { new TextProps { text = text2_json } }, textOption2_2);
var imageProps2 = Constants.MergeImage(
new ImageProps { path = Constants.IMAGE_PATHS.nycSubway.path, x = 7.0, y = 2.45, h = 2.1, w = 3.13 },
shadow2);
slide.addImage(imageProps2);
// type = outer
var textOption3_1 = Constants.MergeTextOption(new TextPropsOptions { x = 0.5, y = 5.0, h = 0.4, w = 6.0 }, Constants.TITLE_STYLE);
slide.addText("Shadow: `type:outer`", textOption3_1);
ImageProps shadow3 = new ImageProps { shadow = new ShadowProps { type = ShadowType.outer, opacity = 0.35, blur = 20, color = "000000", offset = 20, angle = 320 } };
Image URLs path takes a URL or local path from Constants.IMAGE_PATHS; same x/y/h/w geometry. DemoImage.cs · genSlide02
// jpg from local path
slide.addImage(new ImageProps { path = Constants.IMAGE_PATHS.ccLogo.path, x = 0.5, y = 0.6, h = 2.68, w = 3.58 });
// png from local path
slide.addImage(new ImageProps { path = Constants.IMAGE_PATHS.wikimedia2.path, x = 4.6, y = 0.6, h = 2.64, w = 3.45 });
// local file by relative path
slide.addImage(new ImageProps { path = @$"{Constants.IMAGE_PATHS.ccLicenseComp.path}", x = 8.57, y = 0.6, h = 2.52, w = 4.26 });
// wide, url-sourced
slide.addImage(new ImageProps { path = Constants.IMAGE_PATHS.sydneyBridge.path, x = 0.5, y = 4.35, h = 1.8, w = 12.33 });
4Key notes
Path sources resolve through the Constants.IMAGE_PATHS registry (name → path). For in-memory content use data = byte[] instead.
ImageSizingProps(ImageSizingType.crop, w, h, x, y) crops to a viewport of w×h inside the source; the rectangles behind the images on the slide visualise those bounds.
rounding:true clips the picture to rounded corners (false = square). Use it for photo cards.
Shadows are built with ShadowProps { type = inner | outer | none, opacity, blur, color, offset, angle }. The demo renders a JSON copy of each option next to the picture.