0

The method FindPoints detect clouds in weather radar image. The FillPie graphics object is rotating 360 degrees nonstop.

i want to do that when the FillPie(cone) is above any clouds(cloudPoints) color in yellow this clouds that the FillPie(cone) is currently above on.

This is the full code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Doppler_Radar
{
    public partial class Form1 : Form
    {
        int myPiePercent = 15;
        float distanceFromCenterPixels;
        float distanceFromCenterKm = 200F;
        Stream mymem;
        List<Point> cloudPoints = new List<Point>();

        public Form1()
        {
            InitializeComponent();

            pictureBox1.Image = Image.FromFile(@"D:\New folder (4)\Weather Radar\WithClouds.bmp");
            timer1.Enabled = true;
            distanceFromCenterPixels = (float)(183d * (double)distanceFromCenterKm / 200d);
            mymem = ToStream(pictureBox1.Image, ImageFormat.Bmp);
            FindPoints();
        }

        public static Stream ToStream(Image image, ImageFormat formaw)
        {
            var stream = new System.IO.MemoryStream();
            image.Save(stream, formaw);
            stream.Position = 0;
            return stream;
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.DrawRectangle(Pens.Green, 0, 0, pictureBox1.Width - 1, pictureBox1.Height - 1);

            Pen p = new Pen(Color.Red);
            e.Graphics.DrawLine(p, 256, 0, 256, 512);
            e.Graphics.DrawLine(p, 0, 256, 512, 256);

            DrawPieOnPicturebox(e.Graphics);
        }

        public void DrawPieOnPicturebox(Graphics myPieGraphic)
        {
            Color myPieColors = Color.FromArgb(150, Color.LightGreen);
            Size myPieSize = new Size((int)distanceFromCenterPixels, (int)distanceFromCenterPixels);
            Point myPieLocation = new Point((pictureBox1.Width - myPieSize.Width) / 2, (pictureBox1.Height - myPieSize.Height) / 2);
            DrawMyPie(myPiePercent, myPieColors, myPieGraphic, myPieLocation, myPieSize);
        }

        public void DrawMyPie(int myPiePerecent, Color myPieColor, Graphics myPieGraphic, Point
      myPieLocation, Size myPieSize)
        {
            using (SolidBrush brush = new SolidBrush(myPieColor))
            {
                myPieGraphic.FillPie(brush, new Rectangle(myPieLocation, myPieSize), Convert.ToSingle(myPiePerecent * 360 / 100), Convert.ToSingle(15 * 360 / 100));
            }
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            myPiePercent++;
            pictureBox1.Invalidate();
        }

        private void FindPoints()
        {
            Bitmap bmptest;
            GraphicsPath gp = new GraphicsPath();
            int x, y, p, j, wdthHght;
            int bytes;
            byte[] rgbValuesWithClouds;
            byte[] rgbValuesWithoutClouds;
            IntPtr ptr;
            Rectangle rect;
            BitmapData bitmap_Data;

            Bitmap bmpWithClouds; //No memory is allocated
            Bitmap bmpWithoutClouds; //No memory is allocated

            gp.AddEllipse(new RectangleF(73, 72, 367, 367));

            //using the using statement, bmpWithClouds bitmap is automatically disposed at the end of statement. No memory leaks :)
            using (bmpWithClouds = new Bitmap(mymem))
            {
                rect = new Rectangle(0, 0, bmpWithClouds.Width, bmpWithClouds.Height);
                wdthHght = bmpWithClouds.Width;

                //Lock bitmap to copy its color information fast
                bitmap_Data = bmpWithClouds.LockBits(rect, ImageLockMode.ReadWrite, bmpWithClouds.PixelFormat);
                ptr = bitmap_Data.Scan0;
                bytes = bitmap_Data.Stride * bmpWithClouds.Height;

                rgbValuesWithClouds = new byte[bytes];

                //copy color information to rgbValues array
                System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValuesWithClouds, 0, bytes);
                //we are done copying so unlock bitmap. We dont need it anymore
                bmpWithClouds.UnlockBits(bitmap_Data);
            }

            //using the using statement, bmpWithClouds bitmap is automatically disposed at the end of statement. No memory leaks :)
            using (bmpWithoutClouds = new Bitmap(@"F:\Drive Backup\Samsung Galaxy S9\Danny Backup\Recovered data 02-10 18_32_36\1  (D) NTFS\C-Sharp\Weather Radar\WithoutClouds.bmp")) //24 bit bitmap
            {
                rect = new Rectangle(0, 0, bmpWithoutClouds.Width, bmpWithoutClouds.Height);

                //Lock bitmap to copy its color information fast
                bitmap_Data = bmpWithoutClouds.LockBits(rect, ImageLockMode.ReadWrite, bmpWithoutClouds.PixelFormat);
                ptr = bitmap_Data.Scan0;
                bytes = bitmap_Data.Stride * bmpWithoutClouds.Height;

                rgbValuesWithoutClouds = new byte[bytes];

                //copy color information to rgbValues array
                System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValuesWithoutClouds, 0, bytes);
                //we are done copying so unlock bitmap. We dont need it anymore
                bmpWithoutClouds.UnlockBits(bitmap_Data);
            }

            // Each position in these arrays, rgbValuesWithoutClouds and rgbValuesWithClouds, corresponds a color. eg
            // First pixel   Second pixel   Third pixel   Forth pixel .... // bitmaps
            //    B G R          B G R         B G R         B G R    .... // rgbValues arrays
            bmptest = new Bitmap(512, 512);
            cloudPoints = new List<Point>();

            for (y = 0; y < wdthHght; y++)
            {
                j = 0;
                for (x = 0; x < wdthHght; x++)
                {
                    p = y * wdthHght * 3 + j;

                    if (rgbValuesWithClouds[p] != rgbValuesWithoutClouds[p])
                    {
                        cloudPoints.Add(new Point(x, y));
                        bmptest.SetPixel(x, y, Color.Red);
                    }

                    j += 3;
                }
            }
            bmptest.Save(@"d:\bmptest1.bmp");
        }
    }
}

screenshot of the weather radar image with the fillpie cone rotating on it :

radar with fillpie cone

This image is just example to show of what i mean by coloring the clouds when the FillPie(cone) is above any clouds. not many clouds in this image but it's just to give the idea of the coloring :

coloring clouds

and this is the saved bitmap file bmptest1 from the FindPoints method just to show how it looks like when it's detecting the clouds.

clouds

This is what i tried last :

at the top added :

GraphicsPath graphicsPath;

in the constructor added :

graphicsPath = new GraphicsPath();

in the method DrawMyPie i added the line :

graphicsPath.AddPie(new Rectangle(myPieLocation, myPieSize), Convert.ToSingle(myPiePerecent * 360 / 100), Convert.ToSingle(15 * 360 / 100));

then in the FindPoints method i added and changed to this :

if (graphicsPath.IsVisible(x, y))
                        {
                            return;
                        }

                        bmptest.SetPixel(x, y, Color.Yellow);

but it's not coloring in yellow. i guess i need to do something else with the bmptest ?

the complete code with the changes :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Doppler_Radar
{
    public partial class Form1 : Form
    {
        int myPiePercent = 15;
        float distanceFromCenterPixels;
        float distanceFromCenterKm = 200F;
        Stream mymem;
        List<Point> cloudPoints = new List<Point>();
        GraphicsPath graphicsPath;

        public Form1()
        {
            InitializeComponent();

            graphicsPath = new GraphicsPath();
            pictureBox1.Image = Image.FromFile(@"D:\New folder (4)\Weather Radar\WithClouds.bmp");
            timer1.Enabled = true;
            distanceFromCenterPixels = (float)(183d * (double)distanceFromCenterKm / 200d);
            mymem = ToStream(pictureBox1.Image, ImageFormat.Bmp);
            FindPoints();
        }

        public static Stream ToStream(Image image, ImageFormat formaw)
        {
            var stream = new System.IO.MemoryStream();
            image.Save(stream, formaw);
            stream.Position = 0;
            return stream;
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.DrawRectangle(Pens.Green, 0, 0, pictureBox1.Width - 1, pictureBox1.Height - 1);

            Pen p = new Pen(Color.Red);
            e.Graphics.DrawLine(p, 256, 0, 256, 512);
            e.Graphics.DrawLine(p, 0, 256, 512, 256);

            DrawPieOnPicturebox(e.Graphics);
        }

        public void DrawPieOnPicturebox(Graphics myPieGraphic)
        {
            Color myPieColors = Color.FromArgb(150, Color.LightGreen);
            Size myPieSize = new Size((int)distanceFromCenterPixels, (int)distanceFromCenterPixels);
            Point myPieLocation = new Point((pictureBox1.Width - myPieSize.Width) / 2, (pictureBox1.Height - myPieSize.Height) / 2);
            DrawMyPie(myPiePercent, myPieColors, myPieGraphic, myPieLocation, myPieSize);
        }

        public void DrawMyPie(int myPiePerecent, Color myPieColor, Graphics myPieGraphic, Point
      myPieLocation, Size myPieSize)
        {
            using (SolidBrush brush = new SolidBrush(myPieColor))
            {
                myPieGraphic.FillPie(brush, new Rectangle(myPieLocation, myPieSize), Convert.ToSingle(myPiePerecent * 360 / 100), Convert.ToSingle(15 * 360 / 100));
            }

            graphicsPath.AddPie(new Rectangle(myPieLocation, myPieSize), Convert.ToSingle(myPiePerecent * 360 / 100), Convert.ToSingle(15 * 360 / 100));
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            myPiePercent++;
            pictureBox1.Invalidate();
        }

        private void FindPoints()
        {
            Bitmap bmptest;
            GraphicsPath gp = new GraphicsPath();
            int x, y, p, j, wdthHght;
            int bytes;
            byte[] rgbValuesWithClouds;
            byte[] rgbValuesWithoutClouds;
            IntPtr ptr;
            Rectangle rect;
            BitmapData bitmap_Data;

            Bitmap bmpWithClouds; //No memory is allocated
            Bitmap bmpWithoutClouds; //No memory is allocated

            gp.AddEllipse(new RectangleF(73, 72, 367, 367));

            //using the using statement, bmpWithClouds bitmap is automatically disposed at the end of statement. No memory leaks :)
            using (bmpWithClouds = new Bitmap(mymem))
            {
                rect = new Rectangle(0, 0, bmpWithClouds.Width, bmpWithClouds.Height);
                wdthHght = bmpWithClouds.Width;

                //Lock bitmap to copy its color information fast
                bitmap_Data = bmpWithClouds.LockBits(rect, ImageLockMode.ReadWrite, bmpWithClouds.PixelFormat);
                ptr = bitmap_Data.Scan0;
                bytes = bitmap_Data.Stride * bmpWithClouds.Height;

                rgbValuesWithClouds = new byte[bytes];

                //copy color information to rgbValues array
                System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValuesWithClouds, 0, bytes);
                //we are done copying so unlock bitmap. We dont need it anymore
                bmpWithClouds.UnlockBits(bitmap_Data);
            }

            //using the using statement, bmpWithClouds bitmap is automatically disposed at the end of statement. No memory leaks :)
            using (bmpWithoutClouds = new Bitmap(@"F:\Drive Backup\Samsung Galaxy S9\Danny Backup\Recovered data 02-10 18_32_36\1  (D) NTFS\C-Sharp\Weather Radar\WithoutClouds.bmp")) //24 bit bitmap
            {
                rect = new Rectangle(0, 0, bmpWithoutClouds.Width, bmpWithoutClouds.Height);

                //Lock bitmap to copy its color information fast
                bitmap_Data = bmpWithoutClouds.LockBits(rect, ImageLockMode.ReadWrite, bmpWithoutClouds.PixelFormat);
                ptr = bitmap_Data.Scan0;
                bytes = bitmap_Data.Stride * bmpWithoutClouds.Height;

                rgbValuesWithoutClouds = new byte[bytes];

                //copy color information to rgbValues array
                System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValuesWithoutClouds, 0, bytes);
                //we are done copying so unlock bitmap. We dont need it anymore
                bmpWithoutClouds.UnlockBits(bitmap_Data);
            }

            // Each position in these arrays, rgbValuesWithoutClouds and rgbValuesWithClouds, corresponds a color. eg
            // First pixel   Second pixel   Third pixel   Forth pixel .... // bitmaps
            //    B G R          B G R         B G R         B G R    .... // rgbValues arrays
            bmptest = new Bitmap(512, 512);
            cloudPoints = new List<Point>();

            for (y = 0; y < wdthHght; y++)
            {
                j = 0;
                for (x = 0; x < wdthHght; x++)
                {
                    p = y * wdthHght * 3 + j;

                    if (rgbValuesWithClouds[p] != rgbValuesWithoutClouds[p])
                    {
                        cloudPoints.Add(new Point(x, y));

                        if (graphicsPath.IsVisible(x, y))
                        {
                            return;
                        }

                        bmptest.SetPixel(x, y, Color.Yellow);
                    }

                    j += 3;
                }
            }
            bmptest.Save(@"d:\bmptest1.bmp");
        }
    }
}

I tried this way with lockbits but it's very slow now even more then before. it's not working with the rgbvalues1 and 2 condition it's never entering so i removed that line and without that line it's so slow almost the pie cone never move.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Doppler_Radar
{
    public partial class Form1 : Form
    {
        int myPiePercent = 15;
        float distanceFromCenterPixels;
        float distanceFromCenterKm = 200F;
        Stream mymem;
        List<Point> cloudPoints = new List<Point>();
        Bitmap myBitmap;
        GraphicsPath graphicsPath;

        public Form1()
        {
            InitializeComponent();

            graphicsPath = new GraphicsPath();
            pictureBox1.Image = Image.FromFile(@"D:\New folder (4)\Weather Radar\WithClouds.bmp");
            timer1.Enabled = true;
            distanceFromCenterPixels = (float)(183d * (double)distanceFromCenterKm / 200d);
            mymem = ToStream(pictureBox1.Image, ImageFormat.Bmp);
            FindPoints();
        }

        public static Stream ToStream(Image image, ImageFormat formaw)
        {
            var stream = new System.IO.MemoryStream();
            image.Save(stream, formaw);
            stream.Position = 0;
            return stream;
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.DrawRectangle(Pens.Green, 0, 0, pictureBox1.Width - 1, pictureBox1.Height - 1);

            Pen p = new Pen(Color.Red);
            e.Graphics.DrawLine(p, 256, 0, 256, 512);
            e.Graphics.DrawLine(p, 0, 256, 512, 256);

            FindPoints();
            DrawPieOnPicturebox(e.Graphics);
        }

        public void DrawPieOnPicturebox(Graphics myPieGraphic)
        {
            Color myPieColors = Color.FromArgb(150, Color.LightGreen);
            Size myPieSize = new Size((int)distanceFromCenterPixels, (int)distanceFromCenterPixels);
            Point myPieLocation = new Point((pictureBox1.Width - myPieSize.Width) / 2, (pictureBox1.Height - myPieSize.Height) / 2);
            DrawMyPie(myPiePercent, myPieColors, myPieGraphic, myPieLocation, myPieSize);
        }

        public void DrawMyPie(int myPiePerecent, Color myPieColor, Graphics myPieGraphic, Point
      myPieLocation, Size myPieSize)
        {
            using (SolidBrush brush = new SolidBrush(myPieColor))
            {
                myPieGraphic.FillPie(brush, new Rectangle(myPieLocation, myPieSize), Convert.ToSingle(myPiePerecent * 360 / 100), Convert.ToSingle(15 * 360 / 100));
            }

            graphicsPath.AddPie(new Rectangle(myPieLocation, myPieSize), Convert.ToSingle(myPiePerecent * 360 / 100), Convert.ToSingle(15 * 360 / 100));
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            myPiePercent++;
            pictureBox1.Invalidate();
        }

        private Bitmap FindPoints()
        {
            Bitmap bmptest;
            GraphicsPath gp = new GraphicsPath();
            int x, y, wdthHght;
            int p = 0;
            int j = 0;
            int bytes;
            byte[] rgbValuesWithClouds;
            byte[] rgbValuesWithoutClouds;
            IntPtr ptr;
            Rectangle rect;
            BitmapData bitmap_Data;

            Bitmap bmpWithClouds; //No memory is allocated
            Bitmap bmpWithoutClouds; //No memory is allocated

            gp.AddEllipse(new RectangleF(73, 72, 367, 367));

            //using the using statement, bmpWithClouds bitmap is automatically disposed at the end of statement. No memory leaks :)
            using (bmpWithClouds = new Bitmap(mymem))
            {
                rect = new Rectangle(0, 0, bmpWithClouds.Width, bmpWithClouds.Height);
                wdthHght = bmpWithClouds.Width;

                //Lock bitmap to copy its color information fast
                bitmap_Data = bmpWithClouds.LockBits(rect, ImageLockMode.ReadWrite, bmpWithClouds.PixelFormat);
                ptr = bitmap_Data.Scan0;
                bytes = bitmap_Data.Stride * bmpWithClouds.Height;

                rgbValuesWithClouds = new byte[bytes];

                //copy color information to rgbValues array
                System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValuesWithClouds, 0, bytes);
                //we are done copying so unlock bitmap. We dont need it anymore
                bmpWithClouds.UnlockBits(bitmap_Data);
            }

            //using the using statement, bmpWithClouds bitmap is automatically disposed at the end of statement. No memory leaks :)
            using (bmpWithoutClouds = new Bitmap(@"F:\Drive Backup\Samsung Galaxy S9\Danny Backup\Recovered data 02-10 18_32_36\1  (D) NTFS\C-Sharp\Weather Radar\WithoutClouds.bmp")) //24 bit bitmap
            {
                rect = new Rectangle(0, 0, bmpWithoutClouds.Width, bmpWithoutClouds.Height);

                //Lock bitmap to copy its color information fast
                bitmap_Data = bmpWithoutClouds.LockBits(rect, ImageLockMode.ReadWrite, bmpWithoutClouds.PixelFormat);
                ptr = bitmap_Data.Scan0;
                bytes = bitmap_Data.Stride * bmpWithoutClouds.Height;

                rgbValuesWithoutClouds = new byte[bytes];

                //copy color information to rgbValues array
                System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValuesWithoutClouds, 0, bytes);
                //we are done copying so unlock bitmap. We dont need it anymore
                bmpWithoutClouds.UnlockBits(bitmap_Data);
            }

            // Each position in these arrays, rgbValuesWithoutClouds and rgbValuesWithClouds, corresponds a color. eg
            // First pixel   Second pixel   Third pixel   Forth pixel .... // bitmaps
            //    B G R          B G R         B G R         B G R    .... // rgbValues arrays
            bmptest = new Bitmap(512, 512);
            cloudPoints = new List<Point>();

            bmptest = Test(bmptest, rgbValuesWithClouds, rgbValuesWithoutClouds, p);

            return bmptest;
        }

        public unsafe Bitmap Test(Bitmap bmp, byte[] rgbValues1, byte[] rgbValues2, int index)
        {
            int width = bmp.Width;
            int height = bmp.Height;
            //TODO determine bytes per pixel
            int bytesPerPixel = 3; // we assume that image is Format32bppArgb
            int maxPointerLenght = width * height * bytesPerPixel;
            int stride = width * bytesPerPixel;
            byte R, G, B, A;

            BitmapData bData = bmp.LockBits(
                new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
                ImageLockMode.ReadWrite, bmp.PixelFormat);


            byte* scan0 = (byte*)bData.Scan0.ToPointer();

            for (int i = 0; i < maxPointerLenght; i += 3)
            {
                var x = i % bmp.Width;
                var y = i / bmp.Width;

                B = scan0[i + 0];
                G = scan0[i + 1];
                R = scan0[i + 2];
                A = scan0[i + 3];
                if (rgbValues1[index] != rgbValues2[index])
                {
                    cloudPoints.Add(new Point(x, y));

                    if (graphicsPath.IsVisible(x, y))
                    {
                        G = 255;
                        R = 255;
                        B = 0;
                    }
                }
            }


            bmp.UnlockBits(bData);

            return bmp;
        }
    }
}
Shamen Raze
  • 127
  • 6
  • 1
    Something to try. Add the pie to a `GraphicsPath`, set `.SetPixel(x, y, Color.Yellow);` instead of `Color.Red` **WHEN** the pie `GraphicsPath.IsVisible(x, y)` method returns `true`. – dr.null Dec 01 '22 at 18:19
  • @dr.null i tried it and it's not working not coloring in yellow. i edited my question and added in the bottom what i added and changed. i guess i need to do something else in or more in the FindPoints method ? – Shamen Raze Dec 01 '22 at 21:33
  • 1
    You should `if (graphicsPath.IsVisible(x, y)) bmptest.SetPixel(x, y, Color.Yellow);` otherwise different color not the opposite. Also, don't break the loop! – dr.null Dec 01 '22 at 21:39
  • 1
    If you need to collect the yellow pixels only, then `cloudPoints.Add(new Point(x, y));` and `bmptest.SetPixel(x, y, Color.Yellow);` should be within the `if (graphicsPath.IsVisible(x, y)) { ... }` block. But the other pixels of clouds are ignored. Seems not right unless you have them in a separate layer. – dr.null Dec 01 '22 at 21:50
  • @dr.null but what am i doing with the bmptest after it ? now i saved it to the hard disk. but i want to display the yellow clouds when the cone pie is moving over them in the pictureBox image in the first image in my question. – Shamen Raze Dec 01 '22 at 21:54
  • Draw it. Convert the method to a function that returns `bmptest` and draw it before drawing the pie. – dr.null Dec 01 '22 at 21:58
  • @dr.null ok i changed the IF and converted the method to reutn Bitmap and returning the bmptest and now in thew paint event before drawing the pie how do i draw the FindPoints ? I know FindPoints is a bitmap type but how do i draw it ? – Shamen Raze Dec 01 '22 at 22:04
  • `myPieGraphic.DrawImage(bmptest, Point.Empty);`. Make sure the returned bmp size equals the size of the original image. – dr.null Dec 01 '22 at 22:11
  • @dr.null this is working but the pie is moving very very slow now because it's drawing the bitmap with the yellow clouds all the time. myPieGraphic.DrawImage(FindPoints(), Point.Empty); graphicsPath.AddPie(new Rectangle(myPieLocation, myPieSize), Convert.ToSingle(myPiePerecent * 360 / 100), Convert.ToSingle(15 * 360 / 100)); – Shamen Raze Dec 01 '22 at 22:15
  • 1
    You could use 32-bit alpha blending and make the pie wedge semi-transparent. That's just the logic, I'm too lazy to write the code. – Dave S Dec 01 '22 at 22:17
  • `using (Graphics g = Graphics.FromImage(bmp))` Why? Just `e.Graphics.DrawImage(bmp, 0, 0);`. – dr.null Dec 01 '22 at 22:33
  • 1
    Also, use the `LockBits` technique to create the output image instead of the `.SetPixel` way. Much faster. This is what it takes, as I understand from your previous questions. The clouds are moving, the radar is rotating, then you need to find out which parts of the clouds the pie contain. Still too slow? Go for DirectX library. – dr.null Dec 01 '22 at 22:44
  • 1
    @dr.null i will try the lockbits technique but i wish there was a way to do it with the newest directx. my old project used very old directx. – Shamen Raze Dec 01 '22 at 22:49
  • @dr.null when changing the lockbits instead setpixels how do i add then the points to the cloudPOints and how to chheck if the graphicspath is invisible ? i edited my question added to the bottom what i did with the FindPoints. – Shamen Raze Dec 01 '22 at 23:05
  • `var x = i % bmp.Width;`, and `var y = i / bmp.Width;`. See [Fast work with Bitmaps in C#](https://stackoverflow.com/questions/1563038/fast-work-with-bitmaps-in-c-sharp) & [Travel through pixels in BMP](https://stackoverflow.com/questions/6020406/travel-through-pixels-in-bmp). – dr.null Dec 01 '22 at 23:58
  • @dr.null edited my question at the bottom the full code with the lockbits at the bottom of the code. it's not working with the rgbvalues1 and 2 comparison so i removed that line later and then it's very very slow even more then before with the setpixels. – Shamen Raze Dec 02 '22 at 10:05
  • Use [this](https://stackoverflow.com/a/1563170/14171304) routine. The unsafe version. You should advance the pointer correctly based on the image format. Anyways, slow down, breakdown the problem, do every optimization possible. Separate the different tasks and combine the similar ones, use multithreading or `aysnc` programming to do the lengthy/heavy tasks (like downloading the images, extracting frames...), get all the elements ready before drawing the final output in the UI thread. Again, if the overall result is still not accepted, **DirectX** and don't waste your time. – dr.null Dec 02 '22 at 11:01

0 Answers0