Rank: Advanced Member
Groups: Member, Administration, Moderator Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
You need to read an image to get its pixels. So you need to open, close, and reopen an image reader. However, you can write a result directly to Bitmap: Code:Color color;
using (var imageReader = ImageReader.Create(@"..\..\..\largeImage.tif"))
using (var crop = new Crop(0, 0, 1, 1))
using (var bitmap = new Bitmap())
{
Pipeline.Run(imageReader + crop + bitmap);
color = bitmap.GetPixel(0, 0);
}
Console.WriteLine(color);
If you need to get all corner pixels then you can you use a single pipeline: Code:Color topLeftColor, topRightColor, bottomLeftColor, bottomRightColor;
using (var imageReader = ImageReader.Create(@"..\..\..\largeImage.tif"))
using (var topLeftCrop = new Crop(0, 0, 1, 1))
using (var topLeftBitmap = new Bitmap())
using (var topRightCrop = new Crop(imageReader.Width - 1, 0, 1, 1))
using (var topRightBitmap = new Bitmap())
using (var bottomLeftCrop = new Crop(0, imageReader.Height - 1, 1, 1))
using (var bottomLeftBitmap = new Bitmap())
using (var bottomRightCrop = new Crop(imageReader.Width - 1, imageReader.Height - 1, 1, 1))
using (var bottomRightBitmap = new Bitmap())
{
imageReader.Receivers.Add(topLeftCrop);
topLeftCrop.Receivers.Add(topLeftBitmap);
imageReader.Receivers.Add(topRightCrop);
topRightCrop.Receivers.Add(topRightBitmap);
imageReader.Receivers.Add(bottomLeftCrop);
bottomLeftCrop.Receivers.Add(bottomLeftBitmap);
imageReader.Receivers.Add(bottomRightCrop);
bottomRightCrop.Receivers.Add(bottomRightBitmap);
imageReader.RunPipeline();
topLeftColor = topLeftBitmap.GetPixel(0, 0);
topRightColor = topRightBitmap.GetPixel(0, 0);
bottomLeftColor = bottomLeftBitmap.GetPixel(0, 0);
bottomRightColor = bottomRightBitmap.GetPixel(0, 0);
}
Console.WriteLine(topLeftColor);
Console.WriteLine(topRightColor);
Console.WriteLine(bottomLeftColor);
Console.WriteLine(bottomRightColor);
|
Best regards, Fedor Skvortsov
|
![thanks](/Themes/aurigma/heart_small.png) 1 user thanked Fedor for this useful post.
|
|