Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- var handle = new IntPtr();
- string title;
- FindWindowTitleMatch("notepad", out handle, out title);
- var bmp = CaptureApplication(handle);
- bmp.Save(@"C:test.bmp",ImageFormat.Bmp);
- var bmpfromfile = (Bitmap) Image.FromFile(@"C:test.bmp");
- var bytefromfile = ImageToByte(bmpfromfile);
- var bytefromSS = ImageToByte(bmp);
- Console.WriteLine(ByteArrayCompare(bytefromfile, bytefromSS));
- //false
- }
- [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
- static extern int memcmp(byte[] b1, byte[] b2, long count);
- static bool ByteArrayCompare(byte[] b1, byte[] b2)
- {
- // Validate buffers are the same length.
- // This also ensures that the count does not exceed the length of either buffer.
- return b1.Length == b2.Length && memcmp(b1, b2, b1.Length) == 0;
- }
- public static byte[] ImageToByte(Image img)
- {
- ImageConverter converter = new ImageConverter();
- return (byte[])converter.ConvertTo(img, typeof(byte[]));
- }
- public static Bitmap CaptureApplication(IntPtr handle)
- {
- var rect = new User32.Rect();
- User32.GetWindowRect(handle, ref rect);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- var bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
- Graphics graphics = Graphics.FromImage(bmp);
- graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);
- return bmp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement