Image

TsgcHTMLComponent_Image — 渲染一张 Bootstrap 图片,带有形状、响应式尺寸、懒加载以及可选的灯箱和标题,适用于 Delphi、C++ Builder 和 .NET。

TsgcHTMLComponent_Image

一个带 Bootstrap 样式的图片元素。设置来源和替代文本,选择形状,切换响应式和懒加载,然后读取 HTML 属性。

组件类

TsgcHTMLComponent_Image

渲染为

Bootstrap 5 图片标记

语言

Delphi, C++ Builder, .NET

创建它、设置来源、渲染它

赋值 SrcAlt,选择 Shape,切换 ResponsiveLazyLoadLightbox,然后读取 HTML — 或使用静态的一行 Build 辅助方法。

uses
  sgcHTML_Enums, sgcHTML_Component_Image;

var
  oImg: TsgcHTMLComponent_Image;
begin
  oImg := TsgcHTMLComponent_Image.Create(nil);
  try
    oImg.Src := '/img/team.jpg';
    oImg.Alt := 'Our team';
    oImg.Shape := isRounded;
    oImg.Responsive := True;
    oImg.Lightbox := True;
    oImg.Caption := 'The team at work';

    WebModule.Response := oImg.HTML;   // <img> markup
  finally
    oImg.Free;
  end;
end;

// Or in a single line with the static helper:
Result := TsgcHTMLComponent_Image.Build('/img/team.jpg', 'Our team',
  isRounded, True);
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_Image.hpp

TsgcHTMLComponent_Image *oImg = new TsgcHTMLComponent_Image(NULL);
try
{
  oImg->Src = "/img/team.jpg";
  oImg->Alt = "Our team";
  oImg->Shape = isRounded;
  oImg->Responsive = true;
  oImg->Lightbox = true;
  oImg->Caption = "The team at work";

  String html = oImg->HTML;   // <img> markup
}
__finally
{
  delete oImg;
}

// Or in a single line with the static helper:
String html = TsgcHTMLComponent_Image::Build("/img/team.jpg", "Our team",
  isRounded, true);
using esegece.sgcWebSockets;

var img = new TsgcHTMLComponent_Image();
img.Src = "/img/team.jpg";
img.Alt = "Our team";
img.Shape = TsgcHTMLImageShape.isRounded;
img.Responsive = true;
img.Lightbox = true;
img.Caption = "The team at work";

string html = img.HTML;   // <img> markup

// Or in a single line with the static helper:
string oneLine = TsgcHTMLComponent_Image.Build("/img/team.jpg", "Our team",
    TsgcHTMLImageShape.isRounded, true);

关键属性与方法

您最常使用的成员。

来源

Src 设置图片 URL,Alt 设置无障碍替代文本。

形状

ShapeTsgcHTMLImageShapeisRoundedisCircleisThumbnail)设置边角和边框样式。

尺寸

Responsive 应用 img-fluid,使图片随其容器缩放;WidthHeight 设置明确的尺寸。

加载

LazyLoad 添加 loading="lazy",使屏幕外的图片延迟到需要时再加载。

附加功能

Lightbox 将图片包装在指向全尺寸来源的链接中;Caption 将其包装在带标题的 figure 中;ImageID 设置 DOM id。

一行构建

Build(aSrc, aAlt, aShape, aResponsive) 通过单个静态调用返回图片 HTML。

继续探索

所有 sgcHTML 组件浏览 60 多个组件的完整功能矩阵。
下载免费试用版30 天试用版附带 60.HTML 演示项目。
价格Single、Team 和 Site 授权,均含完整源代码。

准备好开始了吗?

下载免费试用版,开始在 Delphi、C++ Builder 和 .NET 中构建 Web 界面。