Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Task
- public void DoWork()
- {
- //Bitmap Array of tiles (Tiles = 3)
- Bitmap[] splits = new Bitmap[tiles];
- //Bitmap for the Screenshot
- var screenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
- //Puffer Bitmap
- Bitmap buffer = new Bitmap(screenshot.Width,screenshot.Height);
- //Calc tile size
- int tilesize = screenshot.Width / tiles;
- // Create a graphics object from the bitmap.
- var gfxScreenshot = Graphics.FromImage(screenshot);
- while (isStarted)
- {
- // Take the screenshot from the upper left corner to the right bottom corner.
- gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
- // Use graphics object from buffer to draw tiles on
- using (Graphics g = Graphics.FromImage(buffer)) //Throws System.InvalidOperationException: "Das Objekt wird bereits an anderer Stelle verwendet." when touching the window
- {
- for (int i = 0; i < tiles; i++)
- {
- //Calculate dimensions for each tile
- Rectangle r = new Rectangle(tilesize * i, 0, tilesize, screenshot.Height);
- //Copy pixels to bitmap array
- splits[i] = screenshot.Clone(r, PixelFormat.Format32bppArgb); //If code gets this far without System.InvalidOperationException it will throw a SystemOutOfMemoryException when over 4Gb.
- //Draw result onto buffer
- g.FillRectangle(
- new SolidBrush(
- ProcessBitmap(splits[i])) //returns a color
- ,r);
- }
- }
- //buffer.Save("Test.png", ImageFormat.Png);
- this.Invoke((MethodInvoker)delegate
- {
- ImageBox.Image = buffer;
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement