客户提出客户端预览图片的时候经常报错,影响操作。经检查是图片异常导致cxImage控件不停的显示异常导致的。
我个人为了省事,直接修改 DevExpress\Library\ExpressEditors5\cxImage.pas 文件
定位到1462行这个函数:procedure TcxImageViewInfo.InternalPaint(ACanvas: TcxCanvas);
增加try except end,省事。。。
try
with ACanvas do
begin
if not Assigned(Picture) or IsPictureEmpty(Picture) then
begin
inherited InternalPaint(ACanvas);
Brush.Color := BackgroundColor;
if Caption <> '' then
begin
Brush.Style := bsClear;
Canvas.Font.Assign(Self.Font);
Canvas.Font.Color := Self.TextColor;
ACanvas.DrawText(Caption, CR, cxAlignCenter + cxSingleLine);
Brush.Style := bsSolid;
end;
if ShowFocusRect then FocusRect(Canvas, CR);
Exit;
end;
with CR do
begin
if Stretch then
begin
CalcStretchRect(CR, Picture.Width, Picture.Height, R);
if Center then
begin
OffsetRect(R, (Right - Left - (R.Right - R.Left)) div 2, 0);
OffsetRect(R, 0, (Bottom - Top - (R.Bottom - R.Top)) div 2);
end;
end
else
begin
R := Rect(Left, Top, Left + Picture.Width, Top + Picture.Height);
if Center then
begin
OffsetRect(R, (Right - Left - Picture.Width) div 2, 0);
OffsetRect(R, 0, (Bottom - Top - Picture.Height) div 2);
end
else
OffsetRect(R, -Self.TopLeft.X, -Self.TopLeft.Y);
end;
end;
SaveRgn := GetClipRegion; // for native mode
ExcludeClipRect(CR);
DrawCustomEdit(ACanvas, Self, False, bpsSolid);
SetClipRegion(SaveRgn, roSet);
if ShowFocusRect then
begin
FocusRect(Canvas, CR);
InflateRect(CR, -1, -1);
end;
SaveRgn := GetClipRegion;
IntersectClipRect(CR);
if ShowFocusRect then InflateRect(CR, 1, 1);
if not Self.Transparent and Picture.Graphic.Transparent then
begin
if FTempBitmap = nil then
begin
FTempBitmap := TBitmap.Create;
FTempBitmap.PixelFormat := pfDevice;
end;
try
FTempBitmap.Width := R.Right - R.Left;
FTempBitmap.Height := R.Bottom - R.Top;
FTempBitmap.Canvas.Brush.Color := BackgroundColor;
FTempBitmap.Canvas.FillRect(Rect(0, 0, FTempBitmap.Width, FTempBitmap.Height));
FTempBitmap.Canvas.StretchDraw(Rect(0, 0, FTempBitmap.Width, FTempBitmap.Height), Picture.Graphic);
Canvas.Draw(R.Left, R.Top, FTempBitmap);
except
on EOutOfResources do
begin
Canvas.Brush.Color := BackgroundColor;
Canvas.FillRect(ClientRect);
Canvas.StretchDraw(R, Picture.Graphic);
end;
end;
end
else
Canvas.StretchDraw(R, Picture.Graphic);
NeedDrawBkg := not (IntersectRect(Temp, R, CR) and EqualRect(Temp, CR)) and not Self.Transparent;
if NeedDrawBkg then
begin
ExcludeClipRect(R);
Brush.Color := BackgroundColor;
FillRect(CR);
end;
SetClipRegion(SaveRgn, roSet);
end;
except
ACanvas.Brush.Color := clWhite;
ACanvas.Canvas.FillRect(ClientRect);
ACanvas.DrawTexT('无法查看此图片,因为此文件可能已损坏、损毁或者过大', ClientRect, DT_VCENTER or DT_CENTER);
end;
try
....................
except
ACanvas.Brush.Color := clWhite;
ACanvas.Canvas.FillRect(ClientRect);
ACanvas.DrawTexT('无法查看此图片,因为此文件可能已损坏、损毁或者过大', ClientRect, DT_VCENTER or DT_CENTER);
end;
此处是我新增部分,其余是原有的,你们还有什么好的处理方式吗?