C
C#2y ago
Fabio

❔ Take screenshot of current screen and return as RasterImage with leadtools...

Im trying to take a screenshot of the primary screen and then convert this 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.MyDoc‌​uments), "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;
}
}
}

}
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.MyDoc‌​uments), "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;
}
}
}

}
the current code returns an error at runtime at RasterImage image = codecs.Load(path, 0, CodecsLoadByteOrder.BgrOrGray, 0, 0);
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server