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:
RKrom 2012-11-04 20:37:39 +00:00
commit 0fd12ae5fc

View file

@ -954,40 +954,61 @@ namespace GreenshotPlugin.Core {
/// <param name="redBitmap">The bitmap taken with a red background</param> /// <param name="redBitmap">The bitmap taken with a red background</param>
/// <param name="cornerColor">The background color</param> /// <param name="cornerColor">The background color</param>
private void RemoveCorners(Bitmap normalBitmap, Bitmap redBitmap, Color cornerColor) { 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)) { using (BitmapBuffer redBuffer = new BitmapBuffer(redBitmap, false)) {
redBuffer.Lock(); redBuffer.Lock();
using (BitmapBuffer normalBuffer = new BitmapBuffer(normalBitmap, false)) { using (BitmapBuffer normalBuffer = new BitmapBuffer(normalBitmap, false)) {
normalBuffer.Lock(); normalBuffer.Lock();
for (int y = 0; y < 8; y++) { // top left
for (int x = 0; x < 8; x++) { for (int y = 0; y < range; y++) {
// top left for (int x = 0; x < range; x++) {
int cornerX = x; Color redBufferPixel = redBuffer.GetColorAt(x, y);
int cornerY = y; Color normalBufferPixel = normalBuffer.GetColorAt(x, y);
Color currentPixel = redBuffer.GetColorAt(cornerX, cornerY); int redDiff = redBufferPixel.R - normalBufferPixel.R;
if (currentPixel.R > 0 && currentPixel.G == 0 && currentPixel.B == 0) { if (redDiff < thresholdTopLeft) {
normalBuffer.SetColorAt(cornerX, cornerY, cornerColor); break;
} }
// top right normalBuffer.SetColorAt(x, y, cornerColor);
cornerX = normalBitmap.Width - x; }
cornerY = y; }
currentPixel = redBuffer.GetColorAt(cornerX, cornerY); // top right
if (currentPixel.R > 0 && currentPixel.G == 0 && currentPixel.B == 0) { for (int y = 0; y < range; y++) {
normalBuffer.SetColorAt(cornerX, cornerY, cornerColor); 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 normalBuffer.SetColorAt(x, y, cornerColor);
cornerX = normalBitmap.Width - x; }
cornerY = normalBitmap.Height - y; }
currentPixel = redBuffer.GetColorAt(cornerX, cornerY); // bottom left
if (currentPixel.R > 0 && currentPixel.G == 0 && currentPixel.B == 0) { for (int y = normalBitmap.Height-1; y > normalBitmap.Height - range; y--) {
normalBuffer.SetColorAt(cornerX, cornerY, cornerColor); 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 normalBuffer.SetColorAt(x, y, cornerColor);
cornerX = x; }
cornerY = normalBitmap.Height - y; }
currentPixel = redBuffer.GetColorAt(cornerX, cornerY); // Bottom right
if (currentPixel.R > 0 && currentPixel.G == 0 && currentPixel.B == 0) { for (int y = normalBitmap.Height-1; y > normalBitmap.Height - range; y--) {
normalBuffer.SetColorAt(cornerX, cornerY, cornerColor); 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);
} }
} }
} }