mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 05:23:24 -07:00
This fixes a bug in the resize logic, the colors of the edges were not calculated correctly by GDI. Also added some additional dispose calls.
This commit is contained in:
parent
823d85ecdd
commit
089eec769e
5 changed files with 22 additions and 12 deletions
|
@ -45,7 +45,6 @@ namespace Greenshot.Drawing.Filters {
|
||||||
|
|
||||||
public unsafe override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
|
public unsafe override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
|
||||||
int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS);
|
int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS);
|
||||||
double previewQuality = GetFieldValueAsDouble(FieldType.PREVIEW_QUALITY);
|
|
||||||
Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
|
Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
|
||||||
if (applyRect.Width == 0 || applyRect.Height == 0) {
|
if (applyRect.Width == 0 || applyRect.Height == 0) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -55,8 +55,9 @@ namespace Greenshot.Drawing.Filters {
|
||||||
graphics.ExcludeClip(rect);
|
graphics.ExcludeClip(rect);
|
||||||
}
|
}
|
||||||
float brightness = GetFieldValueAsFloat(FieldType.BRIGHTNESS);
|
float brightness = GetFieldValueAsFloat(FieldType.BRIGHTNESS);
|
||||||
ImageAttributes ia = ImageHelper.CreateAdjustAttributes(brightness, 1f, 1f);
|
using (ImageAttributes ia = ImageHelper.CreateAdjustAttributes(brightness, 1f, 1f)) {
|
||||||
graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
|
graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
|
||||||
|
}
|
||||||
graphics.Restore(state);
|
graphics.Restore(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,10 @@ namespace Greenshot.Drawing.Filters {
|
||||||
new float[] {0, 0, 0, 1, 0},
|
new float[] {0, 0, 0, 1, 0},
|
||||||
new float[] {0, 0, 0, 0, 1}
|
new float[] {0, 0, 0, 0, 1}
|
||||||
});
|
});
|
||||||
ImageAttributes ia = new ImageAttributes();
|
using (ImageAttributes ia = new ImageAttributes()) {
|
||||||
ia.SetColorMatrix(grayscaleMatrix);
|
ia.SetColorMatrix(grayscaleMatrix);
|
||||||
graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
|
graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
|
||||||
|
}
|
||||||
graphics.Restore(state);
|
graphics.Restore(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -688,6 +688,9 @@ namespace Greenshot.Forms {
|
||||||
// Horizontal middle + 1 to right
|
// Horizontal middle + 1 to right
|
||||||
graphics.DrawRectangle(pen, destinationRectangle.X + halfWidthEnd + 2 * padding, drawAtHeight, halfWidthEnd - 2 * padding - 1, pixelThickness);
|
graphics.DrawRectangle(pen, destinationRectangle.X + halfWidthEnd + 2 * padding, drawAtHeight, halfWidthEnd - 2 * padding - 1, pixelThickness);
|
||||||
}
|
}
|
||||||
|
if (attributes != null) {
|
||||||
|
attributes.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -904,11 +904,12 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <param name="dest">Image to copy to</param>
|
/// <param name="dest">Image to copy to</param>
|
||||||
/// <param name="colorMatrix">ColorMatrix to apply</param>
|
/// <param name="colorMatrix">ColorMatrix to apply</param>
|
||||||
public static void ApplyColorMatrix(Bitmap source, Rectangle sourceRect, Bitmap dest, Rectangle destRect, ColorMatrix colorMatrix) {
|
public static void ApplyColorMatrix(Bitmap source, Rectangle sourceRect, Bitmap dest, Rectangle destRect, ColorMatrix colorMatrix) {
|
||||||
ImageAttributes imageAttributes = new ImageAttributes();
|
using (ImageAttributes imageAttributes = new ImageAttributes()) {
|
||||||
imageAttributes.ClearColorMatrix();
|
imageAttributes.ClearColorMatrix();
|
||||||
imageAttributes.SetColorMatrix(colorMatrix);
|
imageAttributes.SetColorMatrix(colorMatrix);
|
||||||
ApplyImageAttributes(source, sourceRect, dest, destRect, imageAttributes);
|
ApplyImageAttributes(source, sourceRect, dest, destRect, imageAttributes);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Apply image attributes to the image
|
/// Apply image attributes to the image
|
||||||
|
@ -1049,7 +1050,9 @@ namespace GreenshotPlugin.Core {
|
||||||
//create a blank bitmap the same size as original
|
//create a blank bitmap the same size as original
|
||||||
// If using 8bpp than the following exception comes: A Graphics object cannot be created from an image that has an indexed pixel format.
|
// If using 8bpp than the following exception comes: A Graphics object cannot be created from an image that has an indexed pixel format.
|
||||||
Bitmap newBitmap = CreateEmpty(sourceImage.Width, sourceImage.Height, PixelFormat.Format24bppRgb, Color.Empty, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
Bitmap newBitmap = CreateEmpty(sourceImage.Width, sourceImage.Height, PixelFormat.Format24bppRgb, Color.Empty, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||||
ApplyImageAttributes((Bitmap)sourceImage, Rectangle.Empty, newBitmap, Rectangle.Empty, CreateAdjustAttributes(brightness, contrast, gamma));
|
using (ImageAttributes adjustAttributes = CreateAdjustAttributes(brightness, contrast, gamma)) {
|
||||||
|
ApplyImageAttributes((Bitmap)sourceImage, Rectangle.Empty, newBitmap, Rectangle.Empty, adjustAttributes);
|
||||||
|
}
|
||||||
return newBitmap;
|
return newBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1404,7 +1407,10 @@ namespace GreenshotPlugin.Core {
|
||||||
|
|
||||||
using (Graphics graphics = Graphics.FromImage(newImage)) {
|
using (Graphics graphics = Graphics.FromImage(newImage)) {
|
||||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
graphics.DrawImage(sourceImage, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(0, 0, sourceImage.Width, sourceImage.Height), GraphicsUnit.Pixel);
|
using (ImageAttributes wrapMode = new ImageAttributes()) {
|
||||||
|
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
|
||||||
|
graphics.DrawImage(sourceImage, new Rectangle(destX, destY, destWidth, destHeight), 0, 0, sourceImage.Width, sourceImage.Height, GraphicsUnit.Pixel, wrapMode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return newImage;
|
return newImage;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue