How do i resize the Bitmap in this function?
<p>All the time the size is 1920x1080 but i want it to be for example 10x10 so the process in the function will be faster. I dont mind the size of the bitmap or its quality i just want it to be faster.</p>

<p>In this function im creating an histogram of each Bitmap. The problem is that the FOR loops take very long.</p>

<pre><code>public static long[] GetHistogram(Bitmap b)
        {
            long[] myHistogram = new long[256]; // histogram סופר כמה יש מכל גוון

            BitmapData bmData = null;

            //b = new Bitmap(100, 100);
            //b.SetPixel(0,0,Color.FromArgb(10,30,40,50)); //run and make it come to here


            try
            {
                ResizeBitmap(b, 10, 10);
                //Lock it fixed with 32bpp
                bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

                int scanline = bmData.Stride;

                System.IntPtr Scan0 = bmData.Scan0;
                unsafe
                {
                    byte* p = (byte*)(void*)Scan0;
                    int nWidth = b.Width;
                    int nHeight = b.Height;

                    for (int y = 0; y &lt; nHeight; y++)
                    {
                        for (int x = 0; x &lt; nWidth; x++)
                        {
                            long Temp = 0;
                            Temp += p[0]; //  p[0] - blue, p[1] - green , p[2]-red
                            Temp += p[1];
                            Temp += p[2];

                            Temp = (int)Temp / 3;
                            myHistogram[Temp]++;

                            //we do not need to use any offset, we always can increment by pixelsize when
                            //locking in 32bppArgb - mode
                            p += 4;
                        }
                    }
                }

                b.UnlockBits(bmData);
            }
            catch
            {
                try
                {
                    b.UnlockBits(bmData);
                }
                catch
                {

                }
            }

            return myHistogram; // to save to a file the histogram of all the bitmaps/frames each line contain 0 to 256 values of a frame.
        }
</code></pre>

<p>So im calling this function: ResizeBitmap(b, 10, 10);
And try to resize each bitmap but after this line i see that the bitmap size is still 1920x1080</p>

<p>This is the ResizeBitmap function:</p>

<pre><code>public static Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight)
        {
            Bitmap result = new Bitmap(nWidth, nHeight);
            using (Graphics g = Graphics.FromImage((Image)result))
                g.DrawImage(b, 0, 0, nWidth, nHeight);
            return result;
        }
</code></pre>

<p>Maybe there is another way to make the GetHistogram function to work faster ?</p>
