Best FlaUI code snippet using FlaUI.Core.WindowsAPI.Gdi32.StretchBlt
Capture.cs
Source:Capture.cs
...82 {83 // Capture with scaling84 bmp = CaptureDesktopToBitmap(outputRectangle.Width, outputRectangle.Height, (dest, src) =>85 {86 Gdi32.SetStretchBltMode(dest, StretchMode.STRETCH_HALFTONE);87 Gdi32.StretchBlt(dest, outputRectangle.X, outputRectangle.Y, outputRectangle.Width, outputRectangle.Height, src, bounds.X, bounds.Y, bounds.Width, bounds.Height, TernaryRasterOperations.SRCCOPY | TernaryRasterOperations.CAPTUREBLT);88 });89 }90 return new CaptureImage(bmp, bounds, settings);91 }92 private static Bitmap CaptureDesktopToBitmap(int width, int height, Action<IntPtr, IntPtr> action)93 {94 // Use P/Invoke because of: https://stackoverflow.com/a/3072580/106920095 var hDesk = User32.GetDesktopWindow();96 var hSrc = User32.GetWindowDC(hDesk);97 var hDest = Gdi32.CreateCompatibleDC(hSrc);98 var hBmp = Gdi32.CreateCompatibleBitmap(hSrc, width, height);99 var hPrevBmp = Gdi32.SelectObject(hDest, hBmp);100 action(hDest, hSrc);101 var bmp = Image.FromHbitmap(hBmp);...
Gdi32.cs
Source:Gdi32.cs
...14 public static extern IntPtr SelectObject(IntPtr hdc, IntPtr bmp);15 [DllImport("gdi32.dll")]16 public static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int wDest, int hDest, IntPtr hdcSource, int xSrc, int ySrc, CopyPixelOperation rop);17 [DllImport("gdi32.dll")]18 public static extern bool SetStretchBltMode(IntPtr hdc, StretchMode iStretchMode);19 [DllImport("gdi32.dll")]20 public static extern bool StretchBlt(21 IntPtr hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,22 IntPtr hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,23 TernaryRasterOperations dwRop);24 [DllImport("gdi32.dll")]25 public static extern IntPtr DeleteDC(IntPtr hDc);26 [DllImport("gdi32.dll")]27 public static extern IntPtr DeleteObject(IntPtr hDc);28 }29#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member30}...
StretchBlt
Using AI Code Generation
1using System;2using System.Drawing;3using System.Windows.Forms;4using FlaUI.Core.WindowsAPI;5{6 {7 public Form1()8 {9 InitializeComponent();10 }11 private void Form1_Load(object sender, EventArgs e)12 {13 IntPtr handle = FindWindow("Notepad", null);14 if (handle == IntPtr.Zero)15 {16 MessageBox.Show("Window not found");17 return;18 }19 Gdi32.RECT rect;20 Gdi32.GetWindowRect(handle, out rect);21 int width = rect.Right - rect.Left;22 int height = rect.Bottom - rect.Top;23 Bitmap bmp = new Bitmap(width, height);24 Graphics g = Graphics.FromImage(bmp);25 IntPtr hdc = Gdi32.GetDC(handle);26 Gdi32.StretchBlt(g.GetHdc(), 0, 0, width, height, hdc, 0, 0, width, height, Gdi32.SRCCOPY);27 Gdi32.ReleaseDC(handle, hdc);28 bmp.Save("screenshot.bmp");29 g.Dispose();30 }31 [System.Runtime.InteropServices.DllImport("user32.dll")]32 private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);33 }34}
StretchBlt
Using AI Code Generation
1using System;2using System.Drawing;3using System.Runtime.InteropServices;4using System.Windows.Forms;5using FlaUI.Core.WindowsAPI;6{7 {8 public Form1()9 {10 InitializeComponent();11 }12 private void Form1_Load(object sender, EventArgs e)13 {14 Bitmap bmp = new Bitmap(@"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg");15 IntPtr hdc = Gdi32.GetDC(IntPtr.Zero);16 IntPtr hBmp = bmp.GetHbitmap();17 IntPtr hMemDC = Gdi32.CreateCompatibleDC(hdc);18 IntPtr hOldBmp = Gdi32.SelectObject(hMemDC, hBmp);19 Gdi32.StretchBlt(hdc, 0, 0, 200, 200, hMemDC, 0, 0, bmp.Width, bmp.Height, TernaryRasterOperations.SRCCOPY);20 Gdi32.SelectObject(hMemDC, hOldBmp);21 Gdi32.DeleteObject(hBmp);22 Gdi32.DeleteDC(hMemDC);23 Gdi32.ReleaseDC(IntPtr.Zero, hdc);24 }25 }26}
StretchBlt
Using AI Code Generation
1using FlaUI.Core.WindowsAPI;2using System;3using System.Collections.Generic;4using System.Drawing;5using System.Linq;6using System.Text;7using System.Threading.Tasks;8{9 {10 static void Main(string[] args)11 {12 var bitmap = new Bitmap(100, 100);13 var graphics = Graphics.FromImage(bitmap);14 var hdc = graphics.GetHdc();15 var result = Gdi32.StretchBlt(hdc, 0, 0, 100, 100, hdc, 0, 0, 100, 100, Gdi32.TernaryRasterOperations.SRCCOPY);16 graphics.ReleaseHdc(hdc);17 bitmap.Save("test.png");18 }19 }20}21using FlaUI.Core.WindowsAPI;22using System;23using System.Collections.Generic;24using System.rawing;25using System.Linq;26using System.Text;27using System.Threading.Tasks;28{29 {30 static void Main(string[] args)31 {32 var bitmap = new Bitmap(100, 100);33 var graphics = Graphics.FromImage(bitmap);34 var hdc = graphics.GetHdc();35 var result = Gdi32.BitBlt(hdc, 0, 0, 100, 100, hdc, 0, 0, Gdi32.TernaryRasterOperations.SRCOPY);36 graphics.ReleaseHdc(hdc);37 bitmap.Save("test.png");38 }39 }40}41using;42using System;43using System.Collections.Generic;44using System.Drawing;45using System.Linq;46using System.Text;47using System.ThreadingTasks;48{49 {50 static void Main(string[] arg)51 {52 var bitmap = nw Bitmap(100, 100);53 var graphics = Graphics.FomImage(bitmap);54 var hdc = graphics.GetHdc();55 var result = Gdi.BitBlt(hdc,0, 0, 100, 100, hd, 0, 0, Gdi32.TernaryRasterOperations.SRCCOPY);56 graphics.ReeeHdc(hdc);
StretchBlt
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Drawing;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 var bitmap = new Bitmap(100, 100);12 var graphics = Graphics.FromImage(bitmap);13 var hdc = graphics.GetHdc();14 var result = Gdi32.StretchBlt(hdc, 0, 0, 100, 100, hdc, 0, 0, 100, 100, Gdi32.TernaryRasterOperations.SRCCOPY);15 graphics.ReleaseHdc(hdc);16 bitmap.Save("test.png");17 }18 }19}20using FlaUI.Core.WindowsAPI;21using System;22using System.Collections.Generic;23using System.Drawing;24using System.Linq;25using System.Text;26using System.Threading.Tasks;27{28 {29 static void Main(string[] args)30 {31 var bitmap = new Bitmap(100, 100);32 var graphics = Graphics.FromImage(bitmap);33 var hdc = graphics.GetHdc();34 var result = Gdi32.BitBlt(hdc, 0, 0, 100, 100, hdc, 0, 0, Gdi32.TernaryRasterOperations.SRCCOPY);35 graphics.ReleaseHdc(hdc);36 bitmap.Save("test.png");37 }38 }39}40using FlaUI.Core.WindowsAPI;41using System;42using System.Collections.Generic;43using System.Drawing;44using System.Linq;45using System.Text;46using System.Threading.Tasks;47{48 {49 static void Main(string[] args)50 {51 var bitmap = new Bitmap(100, 100);52 var graphics = Graphics.FromImage(bitmap);53 var hdc = graphics.GetHdc();54 var result = Gdi32.BitBlt(hdc, 0, 0, 100, 100, hdc, 0, 0, Gdi32.TernaryRasterOperations.SRCCOPY);55 graphics.ReleaseHdc(hdc);
StretchBlt
Using AI Code Generation
1using FlaUI.Core.WindowsAPI;2using System;3using System.Drawing;4using System.Drawing.Imaging;5using System.Runtime.InteropServices;6using System.Threading;7using System.Windows.Forms;8using FlaUI.Core;9using FlaUI.Core.AutomationElements;10using FlaUI.Core.Definitions;11using FlaUI.Core.Tools;12using FlaUI.UIA3;13{14 {15 static void Main(string[] args)16 {17 var app = Application.Launch(@"C:\Windows\System32\notepad.exe");18 var mainWindow = app.GetMainWindow(new UIA3Automation());19 var rect = mainWindow.Properties.BoundingRectangle.Value;20 var bitmap = new Bitmap(rect.Width, rect.Height);21 var graphics = Graphics.FromImage(bitmap);22 var handle = mainWindow.Properties.NativeWindowHandle.Value;23 var hdc = User32.GetWindowDC(handle);24 var hdcBitmap = graphics.GetHdc();25 var rectWindow = new Rectangle(0, 0, rect.Width, rect.Height);26 Gdi32.StretchBlt(hdcBitmap, 0, 0, rect.Width, rect.Height, hdc, 0, 0, rect.Width, rect.Height, Gdi32.TernaryRasterOperations.SRCCOPY);27 graphics.ReleaseHdc(hdcBitmap);28 User32.ReleaseDC(handle, hdc);29 bitmap.Save("C:\\Users\\Public\\test.png", ImageFormat.Png);30 app.Close();31 }32 }33}
StretchBlt
Using AI Code Generation
1using FlaUI.Core.WindowsAPI;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 [System.Runtime.InteropServices.DllImport("gdi32.dll")]10 public static extern bool StretchBlt(IntPtr hdcDest, int nXOriginDest, int nYOriginDest,11 int nWidthSrc, int nHeightSrc, uint dwRop);12 }13}14using FlaUI.Core.WindowsAPI;15using System;16using System.Collections.Generic;17using System.Linq;18using System.Text;19using System.Threading.Tasks;20{21 {22 [System.Runtime.InteropServices.DllImport("gdi32.dll")]23 public static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth,24 int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);25 }26}27using FlaUI.Core.WindowsAPI;28using System;29using System.Collections.Generic;30using System.Linq;31using System.Text;32using System.Threading.Tasks;33{34 {35 [System.Runtime.InteropServices.DllImport("gdi32.dll")]36 public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth,37 int nHeight);38 }39}40using FlaUI.Core.WindowsAPI;41using System;42using System.Collections.Generic;43using System.Linq;44using System.Text;45using System.Threading.Tasks;46{47 {48 [System.Runtime.InteropServices.DllImport("gdi32.dll")]49 public static extern IntPtr CreateCompatibleDC(IntPtr hdc);50 }51}
StretchBlt
Using AI Code Generation
1using FlaUI.Core.WindowsAPI;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 [System.Runtime.InteropServices.DllImport("gdi32.dll")]10 public static extern bool StretchBlt(IntPtr hdcDest, int nXOriginDest, int nYOriginDest,11 int nWidthSrc, int nHeightSrc, uint dwRop);12 }13}14using FlaUI.Core.WindowsAPI;15using System;16using System.Collections.Generic;17using System.Linq;18using System.Text;19using System.Threading.Tasks;20{21 {22 [System.Runtime.InteropServices.DllImport("gdi32.dll")]23 public static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth,24 int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);25 }26}27using FlaUI.Core.WindowsAPI;28using System;29using System.Collections.Generic;30using System.Linq;31using System.Text;32using System.Threading.Tasks;33{34 {35 [System.Runtime.InteropServices.DllImport("gdi32.dll")]otepad window
StretchBlt
Using AI Code Generation
1using System;2using System.Drawing;3using FlaUI.Core.WindowsAPI;4{5 {6 public static Bitmap CaptureScreen()7 {8 IntPtr desktop = User32.GetDesktopWindow();9 IntPtr hdcSrc = User32.GetWindowDC(desktop);10 User32.RECT windowRect = new User32.RECT();11 User32.GetWindwRec(dskto, ref windowRect);12 int width = windowRect.right - windowRect.left;13 int height = windowRect.bottom - windowRect.top;14 IntPtr hdcDest = Gdi32.CreateComptibleDC(hcSrc);15 IntPtr hBitmap = Gdi32.CreateCompatibleBitmap(hdcSrc, idth, heght);16 ItPtr hOld = Gdi32.SelectObject(hdcDest, hBitmap);17 Gi32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, Gdi32.SRCCOPY);18 Gdi32.SelectObject(hdcDest, hOld);19 Gdi32.DeleteDC(hdcDest);20 User32.ReleaseDC(desktop, hdcSrc);21 Bitmap img = Image.FromHbitmap(hBitmap);22 Gdi32.DeleteObject(hBitmap);23 return img;24 }25 }26}27using System;28using System.Drawing;29using FlaUI.Core.WindowsAPI;30{31 {32 public static Bitmap CaptureScreen()33 {34 IntPtr desktop = User32.GetDesktopWindow();35 User32.RECT windowRect = new User32.RECT();36 User32.GetWindowRect(desktop, ref windowRect);37 int width = windowRect.right - windowRect.left;38 int height = windowRect.bottom - windowRect.top;39 Bitmap img = new Bitmap(width, height);40 Graphics graphics = Graphics.FromImage(img);41 IntPtr hdcBitmap = graphics.GetHdc();42 User32.PrintWindow(desktop, hdcBitmap, 0);43 graphics.ReleaseHdc(hdcBitmap);44 graphics.Dispose();45 return img;46 }47 }48}49using System;50using System.Drawing;51using FlaUI.Core.WindowsAPI;
StretchBlt
Using AI Code Generation
1using System;2using System.Drawing;3using System.Drawing.Imaging;4using System.IO;5using FlaUI.Core.WindowsAPI;6{7 {8 public static void Main(string[] args)9 {10 Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);11 Graphics gfxBmp = Graphics.FromImage(bmp);12 IntPtr hdcBitmap = gfxBmp.GetHdc();13 IntPtr hdcWindow = Gdi32.GetDC(IntPtr.Zero);14 Gdi32.BitBlt(hdcBitmap, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, hdcWindow, 0, 0, Gdi32.SRCCOPY);15 gfxBmp.ReleaseHdc(hdcBitmap);16 Gdi32.ReleaseDC(IntPtr.Zero, hdcWindow);17 bmp.Save("C:\\Users\\Public\\Desktop\\test.png", ImageFormat.Png);18 bmp.Dispose();19 }20 }21}22using System;23using System.Drawing;24using System.Drawing.Imaging;25using System.IO;26using FlaUI.Core.WindowsAPI;27{28 {29 public static void Main(string[] args)30 {31 IntPtr hwndScreen = User32.GetDesktopWindow();32 IntPtr hdcWindow = User32.GetWindowDC(hwndScreen);33 IntPtr hdcMemDC = Gdi32.CreateCompatibleDC(hdcWindow);34 IntPtr hBitmap = Gdi32.CreateCompatibleBitmap(hdcWindow, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);35 public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth,36 int nHeight);37 }38}39using FlaUI.Core.WindowsAPI;40using System;41using System.Collections.Generic;42using System.Linq;43using System.Text;44using System.Threading.Tasks;45{46 { ==IntPtr.Zero47using System;48using System.Drawing;49using System.Drawing.Imaging;50using FlaUI.Core.WindowsAPI;51{52 {53 static void Main(string[] args)54 {55 Bitmap bmp = new Bitmap(200, 200);56 IntPtr hBitmap = bmp.GetHbitmap();57 IntPtr hDC = Gdi32.CreateCompatibleDC(IntPtr.Zero);58 Gdi32.SelectObject(hDC, hBitmap);59 Gdi32.Rectangle(hDC, 0, 0, 200, 200);60 IntPtr hScreenDC Gdi32.GetDC(IntPtr.Zero);61 Gdi32.StretchBlt(hScreenDC, 0, 0, 200,200, hDC, 0, 0, 200, 200, Gdi32.TernaryRasterOperations.SRCCOPY);62 Gdi32.ReleaseDC(ero, hScreenDC);63 Gdi32.DeleteDC(hDC);64 bmp.Save("test.bmp", ImageFomat.Bmp);65 }66 }67}68using System;69using System.Drawing;70using FlaUI.Core.WindowsAPI;71{72 {73 static void Main(string[] args)74 {75 IntPtr hWnd = User32.FindWindow(null, "Notepad");76 User32.GetWindowRect(hWnd, out User32.RECT rect);77 Point p = new Point(rect.Left, rect.Top);78 Size s = new Size(rect.Right - rect.Left, rect.Bottom - rect.Top);79 [System.Runtime.InteropServices.DllImport("gdi32.dll")]80 public static extern IntPtr CreateCompatibleDC(IntPtr hdc);81 }82}
StretchBlt
Using AI Code Generation
1using System;2using System.Drawing;3using System.Drawing.Imaging;4using System.Windows.Forms;5using FlaUI.Core.WindowsAPI;6{7 {8 public static void StretchBlt(IntPtr hdcDest, int xDest, int yDest, int wDest, int hDest, IntPtr hdcSrc, int xSrc, int ySrc, int wSrc, int hSrc, TernaryRasterOperations dwRop)9 {10 var bResult = Gdi32Api.StretchBlt(hdcDest, xDest, yDest, wDest, hDest, hdcSrc, xSrc, ySrc, wSrc, hSrc, dwRop);11 if (bResult == 0)12 {13 throw new Exception("StretchBlt failed");14 }15 }16 }17}18using System;19using System.Drawing;20using System.Drawing.Imaging;21using System.Windows.Forms;22using FlaUI.Core.WindowsAPI;23{24 {25 public static void BitBlt(IntPtr hdcDest, int xDest, int yDest, int wDest, int hDest, IntPtr hdcSrc, int xSrc, int ySrc, TernaryRasterOperations dwRop)26 {27 var bResult = Gdi32Api.BitBlt(hdcDest, xDest, yDest, wDest, hDest, hdcSrc, xSrc, ySrc, dwRop);28 if (bResult == 0)29 {30 throw new Exception("BitBlt failed");31 }32 }33 }34}35using System;36using System.Drawing;37using System.Drawing.Imaging;38using System.Windows.Forms;39using FlaUI.Core.WindowsAPI;40{41 {42 public static IntPtr GetDesktopWindow()43 {44 var result = User32Api.GetDesktopWindow();45 if (result == IntPtr.Zero)46 {47 throw new Exception("GetDesktopWindow failed");48 }49 return result;50 }51 public static IntPtr GetWindowDC(IntPtr hWnd)52 {53 var result = User32Api.GetWindowDC(hWnd);54 if (result == IntPtr.Zero
StretchBlt
Using AI Code Generation
1using System;2using System.Drawing;3using System.Drawing.Imaging;4using FlaUI.Core.WindowsAPI;5{6 {7 static void Main(string[] args)8 {9 Bitmap bmp = new Bitmap(200, 200);10 IntPtr hBitmap = bmp.GetHbitmap();11 IntPtr hDC = Gdi32.CreateCompatibleDC(IntPtr.Zero);12 Gdi32.SelectObject(hDC, hBitmap);13 Gdi32.Rectangle(hDC, 0, 0, 200, 200);14 IntPtr hScreenDC = Gdi32.GetDC(IntPtr.Zero);15 Gdi32.StretchBlt(hScreenDC, 0, 0, 200, 200, hDC, 0, 0, 200, 200, Gdi32.TernaryRasterOperations.SRCCOPY);16 Gdi32.ReleaseDC(IntPtr.Zero, hScreenDC);17 Gdi32.DeleteDC(hDC);18 bmp.Save("test.bmp", ImageFormat.Bmp);19 }20 }21}22using System;23using System.Drawing;24using FlaUI.Core.WindowsAPI;25{26 {27 static void Main(string[] args)28 {29 IntPtr hWnd = User32.FindWindow(null, "Notepad");30 User32.GetWindowRect(hWnd, out User32.RECT rect);31 Point p = new Point(rect.Left, rect.Top);32 Size s = new Size(rect.Right - rect.Left, rect.Bottom - rect.Top);
StretchBlt
Using AI Code Generation
1var gdi32 = new FlaUI.Core.WindowsAPI.Gdi32();2var bitmap = new Bitmap(@"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg");3var hdcScreen = gdi32.GetDC(IntPtr.Zero);4var hdcMem = gdi32.CreateCompatibleDC(hdcScreen);5var hBitmap = IntPtr.Zero;6var hOld = IntPtr.Zero;7{8 hBitmap = bitmap.GetHbitmap(Color.FromArgb(0));9 hOld = gdi32.SelectObject(hdcMem, hBitmap);10 gdi32.StretchBlt(hdcScreen, 0, 0, 1920, 1080, hdcMem, 0, 0, bitmap.Width, bitmap.Height, FlaUI.Core.WindowsAPI.Gdi32.TernaryRasterOperations.SRCCOPY);11}12{13 gdi32.SelectObject(hdcMem, hOld);14 gdi32.DeleteDC(hdcMem);15 gdi32.ReleaseDC(IntPtr.Zero, hdcScreen);16 gdi32.DeleteObject(hBitmap);17}18var gdi32 = new FlaUI.Core.WindowsAPI.Gdi32();19var bitmap = new Bitmap(@"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg");20var hdcScreen = gdi32.GetDC(IntPtr.Zero);21var hdcMem = gdi32.CreateCompatibleDC(hdcScreen);22var hBitmap = IntPtr.Zero;23var hOld = IntPtr.Zero;24{25 hBitmap = bitmap.GetHbitmap(Color.FromArgb(0));26 hOld = gdi32.SelectObject(hdcMem, hBitmap);27 gdi32.StretchBlt(hdcScreen, 0, 0, 1920, 1080, hdcMem, 0, 0, bitmap.Width, bitmap.Height, FlaUI.Core.WindowsAPI.Gdi32.TernaryRasterOperations.SRCCOPY);28}29{30 gdi32.SelectObject(hdcMem, hOld);31 gdi32.DeleteDC(hdcMem);32 gdi32.ReleaseDC(IntPtr.Zero, hdcScreen);33 gdi32.DeleteObject(hBitmap);34}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!