修改一下DELPHI ,cxImage控件显示图片异常时候的情况
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
客戶提出客戶端預(yù)覽圖片的時候經(jīng)常報錯,影響操作。經(jīng)檢查是圖片異常導(dǎo)致cxImage控件不停的顯示異常導(dǎo)致的。
我個人為了省事,直接修改 DevExpress\Library\ExpressEditors5\cxImage.pas 文件
定位到1462行這個函數(shù):procedure TcxImageViewInfo.InternalPaint(ACanvas: TcxCanvas);
增加try except end,省事。。。
trywith ACanvas dobeginif not Assigned(Picture) or IsPictureEmpty(Picture) thenbegininherited InternalPaint(ACanvas);Brush.Color := BackgroundColor;if Caption <> '' thenbeginBrush.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 dobeginif Stretch thenbeginCalcStretchRect(CR, Picture.Width, Picture.Height, R);if Center thenbeginOffsetRect(R, (Right - Left - (R.Right - R.Left)) div 2, 0);OffsetRect(R, 0, (Bottom - Top - (R.Bottom - R.Top)) div 2);end;endelsebeginR := Rect(Left, Top, Left + Picture.Width, Top + Picture.Height);if Center thenbeginOffsetRect(R, (Right - Left - Picture.Width) div 2, 0);OffsetRect(R, 0, (Bottom - Top - Picture.Height) div 2);endelseOffsetRect(R, -Self.TopLeft.X, -Self.TopLeft.Y);end;end;SaveRgn := GetClipRegion; // for native modeExcludeClipRect(CR);DrawCustomEdit(ACanvas, Self, False, bpsSolid);SetClipRegion(SaveRgn, roSet);if ShowFocusRect thenbeginFocusRect(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 thenbeginif FTempBitmap = nil thenbeginFTempBitmap := TBitmap.Create;FTempBitmap.PixelFormat := pfDevice;end;tryFTempBitmap.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);excepton EOutOfResources dobeginCanvas.Brush.Color := BackgroundColor;Canvas.FillRect(ClientRect);Canvas.StretchDraw(R, Picture.Graphic);end;end;endelseCanvas.StretchDraw(R, Picture.Graphic);NeedDrawBkg := not (IntersectRect(Temp, R, CR) and EqualRect(Temp, CR)) and not Self.Transparent;if NeedDrawBkg thenbeginExcludeClipRect(R);Brush.Color := BackgroundColor;FillRect(CR);end;SetClipRegion(SaveRgn, roSet);end;exceptACanvas.Brush.Color := clWhite;ACanvas.Canvas.FillRect(ClientRect);ACanvas.DrawTexT('無法查看此圖片,因?yàn)榇宋募赡芤褤p壞、損毀或者過大', ClientRect, DT_VCENTER or DT_CENTER);end;
try
....................
? except
? ? ACanvas.Brush.Color := clWhite;
? ? ACanvas.Canvas.FillRect(ClientRect);
? ? ACanvas.DrawTexT('無法查看此圖片,因?yàn)榇宋募赡芤褤p壞、損毀或者過大', ClientRect, ? DT_VCENTER or DT_CENTER);
? end;
此處是我新增部分,其余是原有的,你們還有什么好的處理方式嗎?
轉(zhuǎn)載于:https://my.oschina.net/huanghongqiao/blog/727699
總結(jié)
以上是生活随笔為你收集整理的修改一下DELPHI ,cxImage控件显示图片异常时候的情况的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一个生动的例子让你理解Linux的She
- 下一篇: 解决联想笔记本电脑小键盘启动问题的完整指