Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: FillPath and DrawPath do not work on Memory Bitmap #81

Open
MightyM7 opened this issue Jan 14, 2022 · 2 comments
Open

Bug: FillPath and DrawPath do not work on Memory Bitmap #81

MightyM7 opened this issue Jan 14, 2022 · 2 comments

Comments

@MightyM7
Copy link

MightyM7 commented Jan 14, 2022

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
Copy link
Author

Someone an idea? Thanks.

@MightyM7 MightyM7 mentioned this issue Apr 6, 2022
@jingwood
Copy link
Owner

jingwood commented Nov 4, 2022

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants