Firemonkey的旁门左道[八]

前段时间,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;



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值