mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
Trying a different way of cutting the edges
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2235 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
d49a203b3a
commit
0fd12ae5fc
1 changed files with 47 additions and 26 deletions
|
@ -954,40 +954,61 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="redBitmap">The bitmap taken with a red background</param>
|
||||
/// <param name="cornerColor">The background color</param>
|
||||
private void RemoveCorners(Bitmap normalBitmap, Bitmap redBitmap, Color cornerColor) {
|
||||
const int thresholdTopLeft = 60;
|
||||
const int thresholdTopRight = 40;
|
||||
const int thresholdBottomLeft = 45;
|
||||
const int thresholdBottomRight = 35;
|
||||
const int range = 15;
|
||||
using (BitmapBuffer redBuffer = new BitmapBuffer(redBitmap, false)) {
|
||||
redBuffer.Lock();
|
||||
using (BitmapBuffer normalBuffer = new BitmapBuffer(normalBitmap, false)) {
|
||||
normalBuffer.Lock();
|
||||
for (int y = 0; y < 8; y++) {
|
||||
for (int x = 0; x < 8; x++) {
|
||||
// top left
|
||||
int cornerX = x;
|
||||
int cornerY = y;
|
||||
Color currentPixel = redBuffer.GetColorAt(cornerX, cornerY);
|
||||
if (currentPixel.R > 0 && currentPixel.G == 0 && currentPixel.B == 0) {
|
||||
normalBuffer.SetColorAt(cornerX, cornerY, cornerColor);
|
||||
// top left
|
||||
for (int y = 0; y < range; y++) {
|
||||
for (int x = 0; x < range; x++) {
|
||||
Color redBufferPixel = redBuffer.GetColorAt(x, y);
|
||||
Color normalBufferPixel = normalBuffer.GetColorAt(x, y);
|
||||
int redDiff = redBufferPixel.R - normalBufferPixel.R;
|
||||
if (redDiff < thresholdTopLeft) {
|
||||
break;
|
||||
}
|
||||
// top right
|
||||
cornerX = normalBitmap.Width - x;
|
||||
cornerY = y;
|
||||
currentPixel = redBuffer.GetColorAt(cornerX, cornerY);
|
||||
if (currentPixel.R > 0 && currentPixel.G == 0 && currentPixel.B == 0) {
|
||||
normalBuffer.SetColorAt(cornerX, cornerY, cornerColor);
|
||||
normalBuffer.SetColorAt(x, y, cornerColor);
|
||||
}
|
||||
}
|
||||
// top right
|
||||
for (int y = 0; y < range; y++) {
|
||||
for (int x = normalBitmap.Width-1; x > normalBitmap.Width - range; x--) {
|
||||
Color redBufferPixel = redBuffer.GetColorAt(x, y);
|
||||
Color normalBufferPixel = normalBuffer.GetColorAt(x, y);
|
||||
int redDiff = redBufferPixel.R - normalBufferPixel.R;
|
||||
if (redDiff < thresholdTopRight) {
|
||||
break;
|
||||
}
|
||||
// bottom right
|
||||
cornerX = normalBitmap.Width - x;
|
||||
cornerY = normalBitmap.Height - y;
|
||||
currentPixel = redBuffer.GetColorAt(cornerX, cornerY);
|
||||
if (currentPixel.R > 0 && currentPixel.G == 0 && currentPixel.B == 0) {
|
||||
normalBuffer.SetColorAt(cornerX, cornerY, cornerColor);
|
||||
normalBuffer.SetColorAt(x, y, cornerColor);
|
||||
}
|
||||
}
|
||||
// bottom left
|
||||
for (int y = normalBitmap.Height-1; y > normalBitmap.Height - range; y--) {
|
||||
for (int x = 0; x < range; x++) {
|
||||
Color redBufferPixel = redBuffer.GetColorAt(x, y);
|
||||
Color normalBufferPixel = normalBuffer.GetColorAt(x, y);
|
||||
int redDiff = redBufferPixel.R - normalBufferPixel.R;
|
||||
if (redDiff < thresholdBottomLeft) {
|
||||
break;
|
||||
}
|
||||
// bottom left
|
||||
cornerX = x;
|
||||
cornerY = normalBitmap.Height - y;
|
||||
currentPixel = redBuffer.GetColorAt(cornerX, cornerY);
|
||||
if (currentPixel.R > 0 && currentPixel.G == 0 && currentPixel.B == 0) {
|
||||
normalBuffer.SetColorAt(cornerX, cornerY, cornerColor);
|
||||
normalBuffer.SetColorAt(x, y, cornerColor);
|
||||
}
|
||||
}
|
||||
// Bottom right
|
||||
for (int y = normalBitmap.Height-1; y > normalBitmap.Height - range; y--) {
|
||||
for (int x = normalBitmap.Width-1; x > normalBitmap.Width - range; x--) {
|
||||
Color redBufferPixel = redBuffer.GetColorAt(x, y);
|
||||
Color normalBufferPixel = normalBuffer.GetColorAt(x, y);
|
||||
int redDiff = redBufferPixel.R - normalBufferPixel.R;
|
||||
if (redDiff < thresholdBottomRight) {
|
||||
break;
|
||||
}
|
||||
normalBuffer.SetColorAt(x, y, cornerColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue