I am trying to convert a screenshot from my screen as a bitmap into a rasterimage
public static RasterImage TakeScreenShot()
{
// Capture a screenshot of the area of the screen containing the pixel
using (Bitmap screenshot = new Bitmap(1920, 1080))
{
using (Graphics g = Graphics.FromImage(screenshot))
{
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(1920, 1080));
string path = System.IO.Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.MyDocuments), "bitmap.bmp");
screenshot.Save(path);
using (RasterCodecs codecs = new RasterCodecs())
{
RasterImage image = codecs.Load(path, 0, CodecsLoadByteOrder.BgrOrGray, 0, 0);
// The RasterImage object now contains the same image data as the Bitmap object
return image;
}
}
}
}
I am currently getting an error at RasterImage image = codecs.Load(path, 0, CodecsLoadByteOrder.BgrOrGray, 0, 0); "Page not found"
firstPage
1-based index of the first page to load.lastPage
The 1-based index of the last page to load. Must be greater than or equal to firstPage. You can pass -1 to load from firstPage to the last page in the file.
The page index starts with 1
but you pass 0
.
So you could just try this:
RasterImage image = codecs.Load(path, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);