Changeset - adaf02e991b4
[Not reviewed]
default
0 1 0
Jason Maltzen (jmaltzen) - 9 years ago 2015-11-19 03:35:37
jason.maltzen@unsanctioned.net
Fix up screen scraping code to work on retina displays (by converting to an Image and then to a Pixbuf)
1 file changed with 11 insertions and 3 deletions:
0 comments (0 inline, 0 general)
MainWindow.cs
Show inline comments
...
 
@@ -92,10 +92,16 @@ public partial class MainWindow : Gtk.Wi
 
		    	"colors.txt"));
 
		
 
		Build();                      
 
		
 
		if (unmodifiedSwatch != null)
 
		{
 
		unmodifiedSwatch.Clear();
 
		}
 
		if (reactionSwatch != null)
 
		{
 
		reactionSwatch.Clear();
 
		}
 

 
		// get the root window
 
		rootWindow = Gdk.Global.DefaultRootWindow;
 

...
 
@@ -480,10 +486,12 @@ public partial class MainWindow : Gtk.Wi
 
		// Take a screenshot.
 
		byte r, g, b;
 
		int pixelStart, otherPixelStart;
 
		bool colorMatch;
 
		screenBuffer.GetFromDrawable(rootWindow,
 
			rootWindow.Colormap, 0, 0, 0, 0, screenWidth, screenHeight);
 
		Gdk.Image rootImage = rootWindow.GetImage(0, 0, screenWidth, screenHeight);
 
		screenBuffer.GetFromImage(rootImage, rootImage.Colormap, 0, 0, 0, 0, screenWidth, screenHeight);
 
		//screenBuffer.GetFromDrawable(rootWindow,
 
		//	rootWindow.Colormap, 0, 0, 0, 0, screenWidth, screenHeight);
 
		int stride = screenBuffer.Rowstride;
 
		byte* pixBytes = (byte*)screenBuffer.Pixels;
 
				
 
		for (int x = 0; x < screenWidth - colorBarWidth; ++x)
...
 
@@ -581,9 +589,9 @@ public partial class MainWindow : Gtk.Wi
 
								}
 

 
								reactedColor.Blue = (byte)Math.Round((float)pixelCount * 255f / (float)colorBarWidth);
 
								
 
								
 
								// write out the screenshot
 
								// screenBuffer.Save("screenshot.png", "png");
 
								return true;
 
							}
 
						}					
0 comments (0 inline, 0 general)