Ir al contenido


Foto

[TRUCO DELPHI] Usar Canvas en modo Anti-Aliasing.


  • Por favor identifícate para responder
No hay respuestas en este tema

#1 sir.dev.a.lot

sir.dev.a.lot

    Advanced Member

  • Miembros
  • PipPipPip
  • 545 mensajes
  • Location127.0.0.1

Escrito 10 diciembre 2016 - 05:04

[TRUCO DELPHI] Usar Canvas en modo Anti-Aliasing.


delphi
  1. //percent va de 1 a 100, sino no habra efecto
  2. procedure Antialising(C: TCanvas; Rect: TRect; Percent: Integer);
  3. var
  4. l, p: Integer;
  5. R, G, B: Integer;
  6. R1, R2, G1, G2, B1, B2: Byte;
  7. begin
  8. with c do
  9. begin
  10. Brush.Style := bsclear;
  11. lineto(200, 100);
  12. moveto(50, 150);
  13. Ellipse(50, 150, 200, 30);
  14. for l := Rect.Top to Rect.Bottom do
  15. begin
  16. for p := Rect.Left to Rect.Right do
  17. begin
  18. R1 := GetRValue(Pixels[p, l]);
  19. G1 := GetGValue(Pixels[p, l]);
  20. B1 := GetBValue(Pixels[p, l]);
  21.  
  22. R2 := GetRValue(Pixels[p - 1, l]);
  23. G2 := GetGValue(Pixels[p - 1, l]);
  24. B2 := GetBValue(Pixels[p - 1, l]);
  25.  
  26. if (R1 <> R2) or (G1 <> G2) or (B1 <> B2) then
  27. begin
  28. R := Round(R1 + (R2 - R1) * 50 / (Percent + 50));
  29. G := Round(G1 + (G2 - G1) * 50 / (Percent + 50));
  30. B := Round(B1 + (B2 - B1) * 50 / (Percent + 50));
  31. Pixels[p - 1, l] := RGB(R, G, B);
  32. end;
  33.  
  34. R2 := GetRValue(Pixels[p + 1, l]);
  35. G2 := GetGValue(Pixels[p + 1, l]);
  36. B2 := GetBValue(Pixels[p + 1, l]);
  37.  
  38. if (R1 <> R2) or (G1 <> G2) or (B1 <> B2) then
  39. begin
  40. R := Round(R1 + (R2 - R1) * 50 / (Percent + 50));
  41. G := Round(G1 + (G2 - G1) * 50 / (Percent + 50));
  42. B := Round(B1 + (B2 - B1) * 50 / (Percent + 50));
  43. Pixels[p + 1, l] := RGB(R, G, B);
  44. end;
  45.  
  46. R2 := GetRValue(Pixels[p, l - 1]);
  47. G2 := GetGValue(Pixels[p, l - 1]);
  48. B2 := GetBValue(Pixels[p, l - 1]);
  49.  
  50. if (R1 <> R2) or (G1 <> G2) or (B1 <> B2) then
  51. begin
  52. R := Round(R1 + (R2 - R1) * 50 / (Percent + 50));
  53. G := Round(G1 + (G2 - G1) * 50 / (Percent + 50));
  54. B := Round(B1 + (B2 - B1) * 50 / (Percent + 50));
  55. Pixels[p, l - 1] := RGB(R, G, B);
  56. end;
  57.  
  58. R2 := GetRValue(Pixels[p, l + 1]);
  59. G2 := GetGValue(Pixels[p, l + 1]);
  60. B2 := GetBValue(Pixels[p, l + 1]);
  61.  
  62. if (R1 <> R2) or (G1 <> G2) or (B1 <> B2) then
  63. begin
  64. R := Round(R1 + (R2 - R1) * 50 / (Percent + 50));
  65. G := Round(G1 + (G2 - G1) * 50 / (Percent + 50));
  66. B := Round(B1 + (B2 - B1) * 50 / (Percent + 50));
  67. Pixels[p, l + 1] := RGB(R, G, B);
  68. end;
  69. end;
  70. end;
  71. end;
  72. end;

Ejemplo de Uso:


delphi
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3. Antialising(Image1.Canvas, Image1.Canvas.ClipRect, 100);
  4. end;

Saludos!


  • 1




IP.Board spam blocked by CleanTalk.