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
...
 
@@ -90,14 +90,20 @@ public partial class MainWindow : Gtk.Wi
 
		Palette.Load(System.IO.Path.Combine(
 
				System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
 
		    	"colors.txt"));
 
		
 
		Build();                      
 
		
 
		if (unmodifiedSwatch != null)
 
		{
 
		unmodifiedSwatch.Clear();
 
		}
 
		if (reactionSwatch != null)
 
		{
 
		reactionSwatch.Clear();
 
		}
 

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

 
		// get its width and height
 
		rootWindow.GetSize(out screenWidth, out screenHeight);
...
 
@@ -478,14 +484,16 @@ public partial class MainWindow : Gtk.Wi
 
	unsafe bool CaptureReactionColor()
 
	{
 
		// 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)
 
		{
 
			for (int y = 0; y < (screenHeight - 53); ++y)
...
 
@@ -579,13 +587,13 @@ public partial class MainWindow : Gtk.Wi
 
									// pixBytes[otherPixelStart + 2] = 0xFF;
 
									otherPixelStart += 3;
 
								}
 

 
								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)