mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 02:37:03 -07:00
Removed unneeded scroll code. Fixed a potential null-pointer bug in CaptureRectangle. Fixed a bug with GDI captures being black by counting the pixels and if there is a difference taking the screen shot instead.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2238 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
fd46837c8d
commit
35b16e8fd9
4 changed files with 48 additions and 110 deletions
|
@ -762,6 +762,7 @@ namespace Greenshot.Helpers {
|
|||
|
||||
LOG.InfoFormat("Capturing window with mode {0}", windowCaptureMode);
|
||||
bool captureTaken = false;
|
||||
windowRectangle.Intersect(captureForWindow.ScreenBounds);
|
||||
// Try to capture
|
||||
while (!captureTaken) {
|
||||
ICapture tmpCapture = null;
|
||||
|
@ -771,8 +772,49 @@ namespace Greenshot.Helpers {
|
|||
if (windowToCapture.Iconic) {
|
||||
// Restore the window making sure it's visible!
|
||||
windowToCapture.Restore();
|
||||
} else {
|
||||
windowToCapture.ToForeground();
|
||||
}
|
||||
tmpCapture = windowToCapture.CaptureGDIWindow(captureForWindow);
|
||||
if (tmpCapture != null) {
|
||||
// check if GDI capture any good, by comparing it with the screen content
|
||||
int blackCountGDI = ImageHelper.CountColor((Bitmap)tmpCapture.Image, Color.Black, false);
|
||||
int GDIPixels = tmpCapture.Image.Width * tmpCapture.Image.Height;
|
||||
int blackPercentageGDI = (blackCountGDI * 100) / GDIPixels;
|
||||
if (blackPercentageGDI >= 1) {
|
||||
int screenPixels = windowRectangle.Width * windowRectangle.Height;
|
||||
using (ICapture screenCapture = new Capture()) {
|
||||
screenCapture.CaptureDetails = captureForWindow.CaptureDetails;
|
||||
if (WindowCapture.CaptureRectangle(screenCapture, windowRectangle) != null) {
|
||||
int blackCountScreen = ImageHelper.CountColor((Bitmap)screenCapture.Image, Color.Black, false);
|
||||
int blackPercentageScreen = (blackCountScreen * 100) / screenPixels;
|
||||
if (screenPixels == GDIPixels) {
|
||||
// "easy compare", both have the same size
|
||||
// If GDI has more black, use the screen capture.
|
||||
if (blackPercentageGDI > blackPercentageScreen) {
|
||||
LOG.Debug("Using screen capture, as GDI had additional black.");
|
||||
// changeing the image will automatically dispose the previous
|
||||
tmpCapture.Image = screenCapture.Image;
|
||||
// Make sure it's not disposed, else the picture is gone!
|
||||
screenCapture.NullImage();
|
||||
}
|
||||
} else if (screenPixels < GDIPixels) {
|
||||
// Screen capture is cropped, window is outside of screen
|
||||
if (blackPercentageGDI > 50 && blackPercentageGDI > blackPercentageScreen) {
|
||||
LOG.Debug("Using screen capture, as GDI had additional black.");
|
||||
// changeing the image will automatically dispose the previous
|
||||
tmpCapture.Image = screenCapture.Image;
|
||||
// Make sure it's not disposed, else the picture is gone!
|
||||
screenCapture.NullImage();
|
||||
}
|
||||
} else {
|
||||
// Use the GDI capture by doing nothing
|
||||
LOG.Debug("This should not happen, how can there be more screen as GDI pixels?");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tmpCapture != null) {
|
||||
captureForWindow = tmpCapture;
|
||||
|
@ -803,7 +845,7 @@ namespace Greenshot.Helpers {
|
|||
} else {
|
||||
windowToCapture.ToForeground();
|
||||
}
|
||||
windowRectangle.Intersect(captureForWindow.ScreenBounds);
|
||||
|
||||
try {
|
||||
captureForWindow = WindowCapture.CaptureRectangle(captureForWindow, windowRectangle);
|
||||
captureTaken = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue