Я понимаю, что делает следующий код, но я не совсем понимаю каждую строку. Надеюсь, вы, ребята, можете помочь мне с строкой, в которой есть метод CopyPixels, в частности, что делает параметр шага. Не стесняйтесь помогать с другими строками, которые имеют комментарий, если вы будете sh. Очень ценится
BitmapSource bitmapSource = ColorSquare.Source as BitmapSource;
if (bitmapSource != null)
{
double x = Mouse.GetPosition(ColorSquare).X;
//This next line is confusing. It seems like I'm just dividing an image by itself
//say the image width is 4 and since I'm using it as the bitmap source the
//both the PixelWidth and the ActualWidth will = 4, right? Basically x *= 1;
x *= bitmapSource.PixelWidth / ColorSquare.ActualWidth;
if ((int)x > bitmapSource.PixelWidth - 1)
x = bitmapSource.PixelWidth - 1;
else if (x < 0) x = 0;
double y = Mouse.GetPosition(ColorSquare).Y;
y *= bitmapSource.PixelHeight / ColorSquare.ActualHeight;
if ((int)y > bitmapSource.PixelHeight - 1)
y = bitmapSource.PixelHeight - 1;
else if (y < 0) y = 0;
CroppedBitmap cb = new CroppedBitmap(bitmapSource, new Int32Rect((int)x, (int)y, 1, 1));
byte[] pixels = new byte[4];
//What is the stride and why does it need to be 4?
cb.CopyPixels(pixels, 4, 0);
if (pixels[3] == byte.MaxValue)
{
//So it seems we are passing all 4 pixels we copied earlier into the array
//here. This would be the Alpha,Red,Green,Blue of a color. So is that what stride does?
color = Color.FromArgb(pixels[3], pixels[2], pixels[1], pixels[0]);
}
}