Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
Rendimiento Comparando Delphi tCanvas con .Net Graphics

Uso Delphi 10.3 y .Net 5.0. Sé que tCanvas es GDI y Graphics es GDI+, que supera al primero. Pero en los siguientes códigos simples, tCanvas es más rápido. El promedio de 5 milisegundos de Delphi es 185,00 y .Net es 351,20.

¿Por qué tCanvas es más rápido que Graphics o hay alguna falla en mis códigos?

Delfos

 procedure TForm1.PaintBox1Click(Sender: TObject); var _Rectangle: TRect; _Rectangles: TList<TRect>; _Stopwatch: TStopwatch; i: Integer; begin PaintBox1.Canvas.Brush.Color := clWhite; _Rectangle.Left := 0; _Rectangle.Top := 0; _Rectangle.Width := PaintBox1.Width; _Rectangle.Height := PaintBox1.Height; PaintBox1.Canvas.FillRect(_Rectangle); _Rectangles := TList<TRect>.Create; for i := 0 to 9999 do begin _Rectangle.Left := Random(1000); _Rectangle.Top := Random(1000); _Rectangle.Right := _Rectangle.Left + 5; _Rectangle.Bottom := _Rectangle.Top + 5; _Rectangles.Add(_Rectangle); end; PaintBox1.Canvas.Brush.Color := clBlack; _Stopwatch := TStopwatch.StartNew; for i := 0 to 9999 do begin PaintBox1.Canvas.FillRect(_Rectangles.List[i]); end; Caption := IntToStr(_Stopwatch.ElapsedMilliseconds); _Rectangles.Free; end;

.Red

 private void panel1_Click(object sender, EventArgs e) { Graphics _Graphics = panel1.CreateGraphics(); List<Rectangle> _Rectangles = new(); Random _Random = new(); Rectangle _Rectangle = new(0, 0, panel1.Width, panel1.Height); SolidBrush _SolidBrush = new(Color.White); _Graphics.FillRectangle(_SolidBrush, _Rectangle); for (int i = 0; i < 10000; i++) { _Rectangle = new(_Random.Next(1000), _Random.Next(1000), 5, 5); _Rectangles.Add(_Rectangle); } _SolidBrush.Color = Color.Black; Stopwatch _Stopwatch = new(); _Stopwatch.Start(); foreach (var item in _Rectangles) { _Graphics.FillRectangle(_SolidBrush, item); } Text = _Stopwatch.ElapsedMilliseconds.ToString(); _Graphics.Dispose(); _SolidBrush.Dispose(); }
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Siguiendo el consejo de David, el uso de Bitmap mejoró el rendimiento hasta 48,2 milisegundos.

 private void button1_Click(object sender, EventArgs e) { Bitmap _Bitmap = new(1000, 1000); Graphics _BitmapGraphics = Graphics.FromImage(_Bitmap); Graphics _PanelGraphics = panel1.CreateGraphics(); List<Rectangle> _Rectangles = new(); Rectangle _Rectangle; Random _Random = new(); SolidBrush _SolidBrush = new(Color.Black); _BitmapGraphics.Clear(Color.White); for (int i = 0; i < 10000; i++) { _Rectangle = new(_Random.Next(1000), _Random.Next(1000), 5, 5); _Rectangles.Add(_Rectangle); } Stopwatch _Stopwatch = new(); _Stopwatch.Start(); foreach (var item in _Rectangles) { _BitmapGraphics.FillRectangle(_SolidBrush, item); } _PanelGraphics.DrawImage(_Bitmap, Point.Empty); button1.Text = _Stopwatch.ElapsedMilliseconds.ToString(); _Bitmap.Dispose(); _BitmapGraphics.Dispose(); _PanelGraphics.Dispose(); _SolidBrush.Dispose(); }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda