|
|
1
1
method SetShadingAndLogo(const AReport:ReportDocument);
var
LogoPath:String;
PicObj:PictureObject;
Logo:System.Drawing.Image;
PicRatio:Double;
ContWidth, ContHeight:Double;
ContainerRatio:Double;
NewDimension:Double;
PosAdj:Integer;
Scale:Double;
begin
for each Section:Section in AReport.ReportDefinition.Sections do
begin
for each RptObj:ReportObject in Section.ReportObjects do
begin
if RptObj.Name.StartsWith('LOGO', StringComparison.CurrentCultureIgnoreCase) and
(RptObj.Kind = ReportObjectKind.PictureObject) then
begin
//set to company logo
LogoPath := "C:\logo.jpg";
PicObj := RptObj as PictureObject;
if not System.IO.File.Exists(LogoPath) then
PicObj.ObjectFormat.EnableSuppress := true
else
begin
Logo := System.Drawing.Image.FromFile(LogoPath);
//work out the aspect ratios of the image and the container
PicRatio := Double(Logo.Width) / Double(Logo.Height);
//convert twips to pixels
//96 is the default dpi for Windows, but should really check Windows settings
//instead of hard coding
ContWidth := Double(TwipsToPx(PicObj.Width, 96));
ContHeight := Double(TwipsToPx(PicObj.Height, 96));
ContainerRatio := ContWidth / ContHeight;
// adjust the size of the container on the report to maintiain the original
// image's ratio
if PicRatio > ContainerRatio then
begin
// reset the vertical position to remain centred on the original location
// get the new height of the container (in pixels)
NewDimension := (ContWidth / Logo.Width) * Logo.Height;
// get the movement (in twips)
PosAdj := PxToTwips(Integer((ContHeight - NewDimension) / 2), Integer(Logo.VerticalResolution));
// adjust the position
PicObj.Top := PicObj.Top + PosAdj;
// picture is wider so adjust the height accordingly
// need to scale using the logo's dpi to resize correctly
Scale := Double(PicObj.Width) / Double(PxToTwips(Logo.Width, Integer(Logo.VerticalResolution)));
PicObj.Width := Integer(PicObj.Width * Scale);
PicObj.Height := Integer(PicObj.Height * Scale);
end
else
begin
// picture is taller and needs to be scaled to height
// reset the horizontal position to remain centred on the original location
// get the new width of the container (in pixels)
NewDimension := (ContHeight / Logo.Height) * Logo.Width;
// get the movement (in twips)
PosAdj := PxToTwips(Integer((ContWidth - NewDimension) / 2), Integer(Logo.VerticalResolution));
// adjust the position
PicObj.Left := PicObj.Left + PosAdj;
// picture is taller and needs to be scaled to height
// need to scale using the logo's dpi to resize correctly
Scale := Double(PicObj.Height) / Double(PxToTwips(Logo.Height, Integer(Logo.VerticalResolution)));
PicObj.Width := Integer(PicObj.Width * Scale);
PicObj.Height := Integer(PicObj.Height * Scale);
end;
//must free the logo, otherwise Crystal sometimes doesn't display it on report
Logo.Dispose;
for each fm:FormulaFieldDefinition in AReport.DataDefinition.FormulaFields do
begin
if fm.Name.Equals("LogoPath") then
fm.Text := """"+LogoPath+"""";
end;
end;
end;
end;
end;
end;
method TwipsToPx(const AValue, ADpi:Integer):Integer;
begin
//convert to twips using specified dpi, 96 is Windows' default dpi
Result := System.Convert.ToInt32(Double(AValue) * ADpi / 1440);
end;
method PxToTwips(const AValue, ADpi:Integer):Integer;
begin
//convert to pixels using specified dpi, 96 is Windows' default dpi
Result := System.Convert.ToInt32(Double(AValue) * 1440 / ADpi);
end;
|
|
2
0
|
|
|
3
0
在图形位置公式中,您可能需要执行以下操作:-
在报表中,创建“imageUrl”参数字段。按以下步骤进行:- 1) 转到report并打开左边的FieldExplorer。如果它不在那里,你可以去拿它 水晶报表>&燃气轮机;文件浏览器。 2) 右键单击参数字段并单击“新建”
如果有用请告诉我。 |
|
|
user9399808 · 如果单词以特定字符串结尾,则显示数据的公式 8 年前 |
|
|
Asher · 在Crystal报表中分组 8 年前 |
|
|
Sparkind · SQL-需要找到一种方法来检查成员是否已续订 8 年前 |
|
|
user7845219 · 根据公式绘制以下截面的参考底图 8 年前 |
|
|
Jack Frost · 带组的条件计数 8 年前 |
|
|
Jograd Mahusay · Crystal报告未显示数据 8 年前 |