Добавлю, что если требуется считывать более чем один пиксел, и часто, тогда GetPixel - не самый лучший вариант; выгоднее прочитать всю картинку в массив и работать с массивом, чем с GDI+. Пример:
Код | using System; using System.Drawing; using System.Drawing.Imaging;
namespace ConsoleApplication1 { class Class1 { static void Main(string[] args) { string filePath = args[0]; Bitmap bmp = (Bitmap)Bitmap.FromFile(filePath); int W = bmp.Width, H = bmp.Height;
Color[,] array = new Color[H, W];
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); IntPtr ptr = bmpData.Scan0; byte[] rgbValues = new byte[W*H*4]; System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, rgbValues.Length); bmp.UnlockBits(bmpData); int counter = 0; for (int i=0; i<H; i++) for (int j=0; j<W; j++, counter+=4) array[i, j] = Color.FromArgb(rgbValues[counter], rgbValues[counter+1], rgbValues[counter+2]); } } } | |