d2dlib icon indicating copy to clipboard operation
d2dlib copied to clipboard

Bug: FillPath and DrawPath do not work on Memory Bitmap

Open MightyM7 opened this issue 3 years ago • 4 comments

Hi,

I need to draw thousand of pie Elements on my RenderContext. Because the calculation is very time consuming, I need to draw them on a memory bitmap and the the memory bitmap on screen. But this don't work, simply it's nothing drawn but also no error or exception.

I modified your PieChart Example to demonstrate the issue. All other methods work excelent on memory bitmap, but FillPath and DrawPath will not (I've not tested more).

Can you please fix this?

Regards

namespace unvell.D2DLib.Examples.Demos
{
	public partial class PieChart : DemoForm
	{
		List<PieInfo> pies = new List<PieInfo>();
		D2DBitmapGraphics m_MemoryBitmap;

		public PieChart()
		{
			Size = new Size(800, 1000);
			Text = "PieChart Demo - d2dlib Examples";
			CreateChart();
			m_MemoryBitmap = Device.CreateBitmapGraphics(ClientRectangle.Width, ClientRectangle.Height);
		}

		void CreateChart()
		{
			pies.Clear();

			// define the figure origin and size
			var figureOrigin = new D2DPoint(300, 300);
			var figureSize = new D2DSize(300, 300);
			Random random = new Random();

			var records = new float[2];
			records[0] = random.Next(0, 360);
			records[1] = 360 - records[0];

			float currentAngle = 270 - (records[0] / 2);

			// create pie geometries from records
			foreach (var record in records)
			{
				var angleSpan = record;

				var path = Device.CreatePieGeometry(figureOrigin, figureSize, currentAngle, currentAngle + angleSpan);
				pies.Add(new PieInfo { path = path, color = D2DColor.Randomly() });

				currentAngle += angleSpan;
			}

		}

		protected override void OnRender(D2DGraphics g)
		{
			base.OnRender(g);
			// draw background
			D2DBrush brush = Device.CreateSolidColorBrush(D2DColor.Silver);

			m_MemoryBitmap.BeginRender();
			m_MemoryBitmap.FillRectangle(100, 100, 400, 400, D2DColor.LightYellow);
			m_MemoryBitmap.FillEllipse(100, 300, 400, 400, D2DColor.AliceBlue);
			// draw pie geometries
			m_MemoryBitmap.FillPath(pies[0].path, pies[0].color);
			m_MemoryBitmap.DrawPath(pies[0].path, D2DColor.LightYellow, 2);
			//
			m_MemoryBitmap.FillPathWithBrush(pies[0].path, brush);
			//
			m_MemoryBitmap.DrawText("Click to change color", D2DColor.Red, 250, 550);
			m_MemoryBitmap.EndRender();

			g.DrawBitmap(m_MemoryBitmap, ClientRectangle);
			g.FillPathWithBrush(pies[1].path, brush);
			g.DrawPath(pies[1].path, D2DColor.Blue, 2);

			brush.Dispose();
		}

		protected override void OnMouseUp(MouseEventArgs e)
		{
			base.OnMouseUp(e);

			CreateChart();
			Invalidate();
		}
	}

	class PieInfo
	{
		public D2DGeometry path;
		public D2DColor color;
	}
}

MightyM7 avatar Jan 14 '22 16:01 MightyM7

Someone an idea? Thanks.

MightyM7 avatar Feb 21 '22 23:02 MightyM7

I tested your code, and I didn't see any problems there.

Just noticed that there is no FillPathWithBrush method yet, but DrawPath and FillPath work properly with the memory bitmap.

What problem do you get?

m_MemoryBitmap = Device.CreateBitmapGraphics(ClientRectangle.Width, ClientRectangle.Height);

...

m_MemoryBitmap.BeginRender();

foreach (var pie in pies)
{
	// draw pie geometries
	m_MemoryBitmap.FillPath(pie.path, D2DColor.Randomly());
	m_MemoryBitmap.DrawPath(pie.path, D2DColor.Randomly(), 2);
}

//m_MemoryBitmap.FillPathWithBrush(pies[0].path, brush);

m_MemoryBitmap.EndRender();

g.DrawBitmap(m_MemoryBitmap, ClientRectangle);

jingwood avatar Nov 04 '22 03:11 jingwood