C
C#10mo ago
Codemob

C# Custom Screensaver capturing desktop returns solid color

I am working on creating a screen saver in c# dotnet 8.0. I'm currently trying to do something similar to how the bubbles screen saver screenshots your desktop and uses that as a background. Everything works fine, preview mode works, and running the screensaver as an exe works too. The issue occurs when the screen saver actually runs after idling. Windows shows a solid color before running the screensaver so screenshotting just gives that. Program class
c#
static void ShowScreenSaver()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

foreach (Screen screen in Screen.AllScreens)
{
ScreenSaverForm screensaver = new(screen);
screensaver.Show();
screensaver.Refresh();
}
}
c#
static void ShowScreenSaver()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

foreach (Screen screen in Screen.AllScreens)
{
ScreenSaverForm screensaver = new(screen);
screensaver.Show();
screensaver.Refresh();
}
}
ScreenSaverForm class
c#
public Bitmap screenBitmap;
public ScreenSaverForm(Screen screen)
{
screenBitmap = new Bitmap(screen.Bounds.Width, screen.Bounds.Height, PixelFormat.Format24bppRgb);

Graphics captureGraphics = Graphics.FromImage(screenBitmap);

captureGraphics.CopyFromScreen(screen.Bounds.Location, Point.Empty, screen.Bounds.Size);
captureGraphics.Dispose();

InitializeComponent();
StartPosition = FormStartPosition.Manual;
Bounds = screen.Bounds;

timer1.Start();

DoubleBuffered = true;

Paint += ScreenSaverForm_Paint;
}
c#
public Bitmap screenBitmap;
public ScreenSaverForm(Screen screen)
{
screenBitmap = new Bitmap(screen.Bounds.Width, screen.Bounds.Height, PixelFormat.Format24bppRgb);

Graphics captureGraphics = Graphics.FromImage(screenBitmap);

captureGraphics.CopyFromScreen(screen.Bounds.Location, Point.Empty, screen.Bounds.Size);
captureGraphics.Dispose();

InitializeComponent();
StartPosition = FormStartPosition.Manual;
Bounds = screen.Bounds;

timer1.Start();

DoubleBuffered = true;

Paint += ScreenSaverForm_Paint;
}
I tried a tranparent window but the solid color just appears under it. If anyone has any insight as to how the bubbles screensaver accomplishes it or any other alternative way to screenshot under the solid color that would be appreciated!
5 Replies
crayy
crayy10mo ago
Invisible Pixel Extraction Technique could help you here. I've used it on a project before but i could be wrong so try reading into that a little.
deem
deem10mo ago
oh yeah I've used that. It's pretty good. Take a deep dive IPET is the best
Codemob
CodemobOP10mo ago
I've been looking but I don't see how I could get anything meaningful from a solid color
crayy
crayy10mo ago
did you look into the documentation of IPET
Codemob
CodemobOP10mo ago
can you send a link? I can't find very much about it anywhere bump (sorry)

Did you find this page helpful?