前段時間,FMX中如何繪製鋸齒線條讓我苦惱了很長的時間,
幸好有高手相助,這個問題也順利的解決了。
解決方案:
分別修改
FMX.Canvas.Mac.pas
FMX.Canvas.GDIP.pas
兩個單元的代碼, 對於D2D的繪製模式時,FMX.Canvas.GD2D.pas還是無能爲力
真的很奇怪,易博龍爲什麼取消了Canvas.Quality的設置,變成了只讀(接口定義的是讀寫的)所以無法通過正常的流程去修改了。
function TCanvasQuartz.DoBeginScene(const AClipRects: PClipRects = nil; AContextHandle: THandle = 0): Boolean;
begin
if FContext = nil then
begin
if (AContextHandle <> 0) then
FContext := CGContextRef(AContextHandle)
else if Bitmap <> nil then
begin
if Bitmap.Handle <> 0 then
begin
if (TQuartzBitmap(Bitmap.Handle).FImage <> nil) then
begin
CGImageRelease(TQuartzBitmap(Bitmap.Handle).FImage);
TQuartzBitmap(Bitmap.Handle).FImage := nil;
end;
FContext := CGBitmapContextCreate(TQuartzBitmap(Bitmap.Handle).FData, Bitmap.Width, Bitmap.Height, 8,
Bitmap.Width * 4, ColorSpace, kCGImageAlphaPremultipliedLast)
end;
end else if FPrinter is TPrinterMac then
PMSessionGetCGGraphicsContext(TPrinterMac(FPrinter).PrintInfo.PMPrintSession, @FContext);
if Assigned(FContext) then
CGContextSetShouldAntialias(FContext, 0); // 鋸齒
end;
FFontScale := 1;
if Assigned(FPrinter) and (TPrinterMac(FPrinter).ActivePrinter.ActiveDPIIndex >= 0) then
FFontScale := TPrinterMac(FPrinter).ActivePrinter.ActiveDPI.X / 96;
Result := inherited DoBeginScene(AClipRects) and (FContext <> nil);
if Result and (AClipRects <> nil) then
SetClipRects(AClipRects^);
end;
constructor TCanvasGdiPlus.CreateFromWindow(const AParent: TWindowHandle; const AWidth, AHeight: Integer;
const AQuality: TCanvasQuality = TCanvasQuality.ccSystemDefault);
begin
inherited CreateFromWindow(AParent, AWidth, AHeight, AQuality);
WindowHandleToPlatform(Parent).CreateBuffer(Width, Height);
FGPGraphics := TGPGraphics.Create(WindowHandleToPlatform(Parent).BufferHandle);
FGPGraphics.SetPixelOffsetMode(PixelOffsetModeHalf);
// case Quality of
// TCanvasQuality.ccHighPerformance: FGPGraphics.SetSmoothingMode(SmoothingModeHighSpeed);
// TCanvasQuality.ccHighQuality: FGPGraphics.SetSmoothingMode(SmoothingModeAntiAlias);
// else
// FGPGraphics.SetSmoothingMode(SmoothingModeAntiAlias);
// end;
FGPGraphics.SetSmoothingMode(SmoothingModeHighSpeed); //鋸齒
FGPGraphics.SetInterpolationMode(InterpolationModeHighQuality);
FGPGraphics.SetTextContrast(TextContrast);
if GlobalUseGDIPlusClearType then
FGPGraphics.SetTextRenderingHint(TextRenderingHintClearTypeGridFit)
else
FGPGraphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
FGPPen := TGPPen.Create($FF000000);
FGPPenBrush := TGPSolidBrush.Create($FF000000);
FGPBrush := TGPSolidBrush.Create($FFFFFFFF);
FGPFamily := TGPFontFamily.Create('Tahoma');
FFontScale := 1;
end;
constructor TCanvasGdiPlus.CreateFromBitmap(const ABitmap: TBitmap; const AQuality: TCanvasQuality = TCanvasQuality.ccSystemDefault);
begin
inherited CreateFromBitmap(ABitmap, AQuality);
FGPGraphics := TGPGraphics.Create(TGPBitmap(Bitmap.Handle));
FGPGraphics.SetPixelOffsetMode(PixelOffsetModeHalf);
// case Quality of
// TCanvasQuality.ccHighPerformance: FGPGraphics.SetSmoothingMode(SmoothingModeHighSpeed);
// TCanvasQuality.ccHighQuality: FGPGraphics.SetSmoothingMode(SmoothingModeAntiAlias);
// else
// FGPGraphics.SetSmoothingMode(SmoothingModeAntiAlias);
// end;
FGPGraphics.SetSmoothingMode(SmoothingModeHighSpeed);; // 鋸齒
FGPGraphics.SetTextContrast(TextContrast);
if GlobalUseGDIPlusClearType then
FGPGraphics.SetTextRenderingHint(TextRenderingHintClearTypeGridFit)
else
FGPGraphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
FGPPen := TGPPen.Create($FF000000);
FGPPenBrush := TGPSolidBrush.Create($FF000000);
FGPBrush := TGPSolidBrush.Create($FFFFFFFF);
FGPFamily := TGPFontFamily.Create('Tahoma');
if (Width > 0) and (Height > 0) and not SameValue(FGPGraphics.GetDpiX, 0.0, Epsilon) then
FFontScale := 96 / FGPGraphics.GetDpiX
else
FFontScale := 1;
end;
procedure TCanvasGdiPlus.SetSize(const AWidth, AHeight: Integer);
begin
if Assigned(Parent) and ((AWidth <> Width) or (AHeight <> Height)) then
begin
inherited ;
FreeAndNil(FGPGraphics);
WindowHandleToPlatform(Parent).ResizeBuffer(Width, Height);
FGPGraphics := TGPGraphics.Create(WindowHandleToPlatform(Parent).BufferHandle);
// FGPGraphics.SetSmoothingMode(SmothingDefault);
FGPGraphics.SetSmoothingMode(SmoothingModeHighSpeed); //鋸齒
FGPGraphics.SetPixelOffsetMode(PixelOffsetModeHalf);
FGPGraphics.SetInterpolationMode(InterpolationModeHighQuality);
FGPGraphics.SetTextContrast(TextContrast);
if GlobalUseGDIPlusClearType then
FGPGraphics.SetTextRenderingHint(TextRenderingHintClearTypeGridFit)
else
FGPGraphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
FGPPen := TGPPen.Create($FF000000);
FGPPenBrush := TGPSolidBrush.Create($FF000000);
FGPBrush := TGPSolidBrush.Create($FFFFFFFF);
FGPFamily := TGPFontFamily.Create('Tahoma');
FFontScale := 1;
end
else
inherited ;
end;