在有些时候客户需要对文档内是否存在图片进行检测,可以检测文档背景是否包含图片,文档内是否存在图片,图片列表、列表标记是否有图片,表格背景是否有图片,表格单元格背景是否有图片等,
TRichView文档编辑控件提供了丰富的API,可以帮助开发人员进行快速的检测,下面是实现该功能的部分代码,如果需要完整的事例可以安装该产品的试用版,安装以后会有相关的事例。
function RVDataHasImage(RVData: TCustomRVData): Boolean;
var
i,r,c: Integer;
ListNo, LevelNo, StartFrom: Integer;
UseStartFrom: Boolean;
Table: TRVTableItemInfo;
ListLevels: TRVListLevelCollection;
begin
Result := True;
for i := 0 to RVData.ItemCount-1 do
case RVData.GetItemStyle(i) of
rvsPicture, rvsHotPicture, rvsBullet, rvsHotspot:
exit;
rvsListMarker:
begin
RVData.GetListMarkerInfo(i, ListNo, LevelNo, StartFrom, UseStartFrom);
if (ListNo<0) then
continue;
ListLevels := RVData.GetRVStyle.ListStyles[ListNo].Levels;
if LevelNo>=ListLevels.Count then
LevelNo := ListLevels.Count-1;
if (LevelNo<0) then
continue;
if ListLevels[LevelNo].ListType in [rvlstPicture, rvlstImageList, rvlstImageListCounter] then
exit;
end;
rvsTable:
begin
Table := TRVTableItemInfo(RVData.GetItem(i));
if (Table.BackgroundStyle<>rvbsColor) and (Table.BackgroundImage<>nil) then
exit;
for r := 0 to Table.RowCount - 1 do
for c := 0 to Table.ColCount - 1 do
if Table.Cells[r,c]<>nil then
begin
if (Table.Cells[r,c].BackgroundStyle<>rvbsColor) and
(Table.Cells[r,c].BackgroundImage<>nil) then
exit;
if RVDataHasImage(Table.Cells[r,c].GetRVData) then
exit;
end;
end;
rvsFootnote, rvsEndnote, rvsSidenote, rvsTextBox:
if RVDataHasImage(TCustomRVNoteItemInfo(RVData.GetItem(i)).Document) then
exit;
end;
Result := False;
end;
function HasImage(rv: TCustomRichView): Boolean;
begin
Result := ((rv.BackgroundStyle<>bsNoBitmap) and not rv.BackgroundBitmap.Empty) or
RVDataHasImage(rv.RVData);
end;