1

I wonder if it´s possible to take a screenshot, and only keep it IF it is different from the last one.

so currently i am using this function.

private static MemoryStream PrintWindow(string prcname)
{
    IntPtr hwnd;
    using (var proc = Process.GetProcessesByName(prcname)[0])
    {
        hwnd = proc.MainWindowHandle;
    }
    Rect rc;
    NativeMethods.GetWindowRect(hwnd, out rc);
    using (Bitmap bmp = new Bitmap(rc.Width, rc.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb))
    {
        using (Graphics gfxBmp = Graphics.FromImage(bmp))
        {
            IntPtr hdcBitmap = gfxBmp.GetHdc();
            try
            {
                NativeMethods.PrintWindow(hwnd, hdcBitmap, 0);
            }
            finally
            {
                gfxBmp.ReleaseHdc(hdcBitmap);
            }
        }
        MemoryStream ms = new MemoryStream();
        bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
        return ms;
    }
}

And then i send the image over the net and display it on the other side.

Now, i wonder if it´s possible to just send when a new image has been taking. or well, not new, but another image. Let´s say it takes 10 images, and all of them looks exactly the same, and it´s just unnecessary to use all of those 10 images and send them, as the the other side could just "pause" at that last image until a new image has occured.

Hope you understand what i am trying to explain here.

Zerowalker
  • 761
  • 2
  • 8
  • 27
  • 1
    If you want some function which will check if two bitmaps are identical, check this one out: http://stackoverflow.com/questions/2031217/what-is-the-fastest-way-i-can-compare-two-equal-size-bitmaps-to-determine-whethe – Kamil T Aug 06 '13 at 09:52
  • Image different how? file size? picture? If its the latter then the performance overhead is probably greater than just showing the new image – Sayse Aug 06 '13 at 09:53
  • Compare just the size, as that should be extremely fast right? just have an int or something with the length of the image, then compare it to the next image, if the same throw it away if not, give that size to the int. – Zerowalker Aug 06 '13 at 10:02
  • Okay i actually solved it myself by doing that – Zerowalker Aug 06 '13 at 10:16

1 Answers1

0

Funny enough i solve it when i answered Sayse.

So here is what i did.

First i runt that function and get a memorystream with an image in it.

Then i do like this:

                        if (bsize != ms.Length)
                        {
                            bsize = ms.Length;
                            writer.Write((int)ms.Length);
                            writer.Write(ms.GetBuffer(), 0, (int)ms.Length);
                        }

So it´s really easy. bsize is long.

So it takes a screenshot, put it in a memorystream. The If that memorystream length is different from bsize, it will send it.

Now the first run, it´s always different, as bsize is null. Then it will set bsize to the length of that memorystream.

So if the next one is the same, it will just ignore that, if it´s not, it will repeat and put that length to bsize.

Now this is probably not the best way to do it, but it works and it seems to work well:)

PS: This does NOT work with .bmp, as uncompressed is the same size depending on resolution, not content.

Zerowalker
  • 761
  • 2
  • 8
  • 27