mirror of
https://github.com/greenshot/greenshot
synced 2025-08-13 18:27:03 -07:00
This change enables a transparent background for those parts in the screen capture which are not visible on the screen.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2347 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
3a5b3d63a9
commit
03cba68f61
1 changed files with 42 additions and 3 deletions
|
@ -701,10 +701,49 @@ namespace GreenshotPlugin.Core {
|
||||||
// A suggestion for the "A generic error occurred in GDI+." E_FAIL/0×80004005 error is to re-try...
|
// A suggestion for the "A generic error occurred in GDI+." E_FAIL/0×80004005 error is to re-try...
|
||||||
bool success = false;
|
bool success = false;
|
||||||
ExternalException exception = null;
|
ExternalException exception = null;
|
||||||
for(int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
try {
|
try {
|
||||||
// assign image to Capture, the image will be disposed there..
|
// Collect all screens inside this capture
|
||||||
returnBitmap = Bitmap.FromHbitmap(hDIBSection);
|
List<Screen> screensInsideCapture = new List<Screen>();
|
||||||
|
foreach (Screen screen in Screen.AllScreens) {
|
||||||
|
if (screen.Bounds.IntersectsWith(captureBounds)) {
|
||||||
|
screensInsideCapture.Add(screen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check all all screens are of an equal size
|
||||||
|
bool offscreenContent = false;
|
||||||
|
using (Region captureRegion = new Region(captureBounds)) {
|
||||||
|
// Exclude every visible part
|
||||||
|
foreach (Screen screen in screensInsideCapture) {
|
||||||
|
captureRegion.Exclude(screen.Bounds);
|
||||||
|
}
|
||||||
|
// If the region is not empty, we have "offscreenContent"
|
||||||
|
using (Graphics screenGraphics = Graphics.FromHwnd(User32.GetDesktopWindow())) {
|
||||||
|
offscreenContent = !captureRegion.IsEmpty(screenGraphics);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check if we need to have a transparent background, needed for offscreen content
|
||||||
|
if (offscreenContent) {
|
||||||
|
using (Bitmap tmpBitmap = Bitmap.FromHbitmap(hDIBSection)) {
|
||||||
|
// Create a new bitmap which has a transparent background
|
||||||
|
returnBitmap = ImageHelper.CreateEmpty(tmpBitmap.Width, tmpBitmap.Height, PixelFormat.Format32bppArgb, Color.Transparent, tmpBitmap.HorizontalResolution, tmpBitmap.VerticalResolution);
|
||||||
|
// Content will be copied here
|
||||||
|
using (Graphics graphics = Graphics.FromImage(returnBitmap)) {
|
||||||
|
// For all screens copy the content to the new bitmap
|
||||||
|
foreach (Screen screen in Screen.AllScreens) {
|
||||||
|
Rectangle screenBounds = screen.Bounds;
|
||||||
|
// Make sure the bounds are offsetted to the capture bounds
|
||||||
|
screenBounds.Offset(-captureBounds.X, -captureBounds.Y);
|
||||||
|
graphics.DrawImage(tmpBitmap, screenBounds, screenBounds.X, screenBounds.Y, screenBounds.Width, screenBounds.Height, GraphicsUnit.Pixel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// All screens, which are inside the capture, are of equal size
|
||||||
|
// assign image to Capture, the image will be disposed there..
|
||||||
|
returnBitmap = Bitmap.FromHbitmap(hDIBSection);
|
||||||
|
}
|
||||||
|
// We got through the capture without exception
|
||||||
success = true;
|
success = true;
|
||||||
break;
|
break;
|
||||||
} catch (ExternalException ee) {
|
} catch (ExternalException ee) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue