BitmapImage image = new BitmapImage(new Uri("image.png", UriKind.Relative)); int[] pixels = new int[image.PixelWidth * image.PixelHeight]; image.CopyPixels(pixels, image.PixelWidth * sizeof(int), 0);
BitmapImage image = new BitmapImage(new Uri("image.png", UriKind.Relative)); int[] pixels = new int[100 * 100]; int stride = 100 * sizeof(int); int offset = 500 * stride; // Start copying at pixel location (500, 500) image.CopyPixels(new Int32Rect(500, 500, 100, 100), pixels, stride, offset);In this example, we create a BitmapImage object and an array of integers as before. However, this time we specify a subset of the image to be copied using an Int32Rect object that specifies the top-left corner of the rectangle and its width and height. We also specify the stride and offset to start copying from a specific location. The package library for the BitmapImage class is the PresentationCore.dll.