ImageProcessor.Imaging.FastBitmap.GetPixel C# (CSharp) Метод

GetPixel() публичный Метод

Gets the color at the specified pixel of the System.Drawing.Bitmap.
public GetPixel ( int x, int y ) : Color
x int The x-coordinate of the pixel to retrieve.
y int The y-coordinate of the pixel to retrieve.
Результат Color
        public Color GetPixel(int x, int y)
        {
            #if DEBUG
            if ((x < 0) || (x >= this.width))
            {
                throw new ArgumentOutOfRangeException("x", "Value cannot be less than zero or greater than the bitmap width.");
            }

            if ((y < 0) || (y >= this.height))
            {
                throw new ArgumentOutOfRangeException("y", "Value cannot be less than zero or greater than the bitmap height.");
            }
            #endif
            Color32* data = this[x, y];
            return Color.FromArgb(data->A, data->R, data->G, data->B);
        }

Usage Example

Пример #1
0
        public static Bitmap ResizeNearestNeighbor(Bitmap source, int width, int height, Rectangle destinationRectangle)
        {
            int sourceWidth  = source.Width;
            int sourceHeight = source.Height;
            int startX       = destinationRectangle.X;
            int startY       = destinationRectangle.Y;
            int endX         = destinationRectangle.Width + startX;
            int endY         = destinationRectangle.Height + startY;

            // Scaling factors
            double widthFactor  = sourceWidth / (double)destinationRectangle.Width;
            double heightFactor = sourceHeight / (double)destinationRectangle.Height;

            Bitmap destination = new Bitmap(width, height, PixelFormat.Format32bppPArgb);

            destination.SetResolution(source.HorizontalResolution, source.VerticalResolution);

            using (FastBitmap sourceBitmap = new FastBitmap(source))
            {
                using (FastBitmap destinationBitmap = new FastBitmap(destination))
                {
                    // For each column
                    Parallel.For(
                        startY,
                        endY,
                        y =>
                    {
                        if (y >= 0 && y < height)
                        {
                            // Y coordinates of source points
                            int originY = (int)((y - startY) * heightFactor);

                            for (int x = startX; x < endX; x++)
                            {
                                if (x >= 0 && x < width)
                                {
                                    // X coordinates of source points
                                    int originX = (int)((x - startX) * widthFactor);

                                    destinationBitmap.SetPixel(x, y, sourceBitmap.GetPixel(originX, originY));
                                }
                            }
                        }
                    });
                }
            }

            source.Dispose();
            return(destination);
        }
All Usage Examples Of ImageProcessor.Imaging.FastBitmap::GetPixel