How to read the Color of a Screen Pixel

This is the most efficient: It grabs a pixel at the location of the cursor, and doesn’t rely on only having one monitor. using System; using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices; using System.Windows.Forms; using System.Diagnostics; namespace FormTest { public partial class Form1 : Form { [DllImport(“user32.dll”)] static extern bool GetCursorPos(ref Point lpPoint); [DllImport(“gdi32.dll”, CharSet = … Read more

Resize image proportionally with MaxHeight and MaxWidth constraints

Like this? public static void Test() { using (var image = Image.FromFile(@”c:\logo.png”)) using (var newImage = ScaleImage(image, 300, 400)) { newImage.Save(@”c:\test.png”, ImageFormat.Png); } } public static Image ScaleImage(Image image, int maxWidth, int maxHeight) { var ratioX = (double)maxWidth / image.Width; var ratioY = (double)maxHeight / image.Height; var ratio = Math.Min(ratioX, ratioY); var newWidth = (int)(image.Width … Read more