0

Using a sliced strock as a timer

I already have the use of a running sliced strock like a timer. I wanted to do the same with a picture with rounded corners, but it didn't work and it was cropped for a round one.

Real and Cropped after slice

This is the code I used:

    for (int i = 0; i <= 100; i++)
    {
        Bitmap bitmap2 = Pie(bitmap, i);
        var ms = new MemoryStream();
        bitmap2.Save(ms, ImageFormat.Png);
        RendererManager.LoadImage("NewVisuals.roundedRect" + i, ms);
    }

    public static Bitmap Pie(System.Drawing.Image source, int pct)
    {
        Bitmap bitmap = new Bitmap(source.Width, source.Height);
        using GraphicsPath graphicsPath = new GraphicsPath();
        graphicsPath.AddArc(0, 0, source.Width, source.Height, -90f, 3.6f * (float)pct);
        using Graphics graphics = Graphics.FromImage(bitmap);
        graphics.SetClip(graphicsPath);
        graphics.DrawImage(source, 0, 0, source.Width, source.Height);
        return bitmap;
    }

How can I avoid cutting corners, but just slice the picture as shown in the example? Example what i need

Find out how you can slice the outline for later use

Aloex
  • 3
  • 4
  • You're adding a single arc, which is not a closed figure. You cannot clip a device context on that. Was that arc meant to draw the elapsed time around the clock image? If you want to create a circular clip region, use `graphicsPath.AddArc(rect, -90, 360);`, where `rect` represents the Bitmaps bounds. Otherwise, you have to define all the arcs that complete the figure, as shown, e.g., [here](https://stackoverflow.com/a/54794097/7444103) or [here](https://stackoverflow.com/a/56533229/7444103) (remember to call `[GraphicsPtah].CloseFigure()` when all arcs are added) – Jimi Nov 26 '22 at 17:50

0 Answers0