Firemonkey的旁門左道[八]

來源:互聯網
上載者:User

前段時間,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;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.