diff --git a/Greenshot/Drawing/Surface.cs b/Greenshot/Drawing/Surface.cs
index ca5c75443..f81f7a099 100644
--- a/Greenshot/Drawing/Surface.cs
+++ b/Greenshot/Drawing/Surface.cs
@@ -605,16 +605,14 @@ namespace Greenshot.Drawing {
try {
Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size);
Bitmap newImage = null;
- Point offset = Point.Empty;
+ Point offset = new Point(-1,-1);
switch (effect) {
case Effects.Shadow:
- offset = new Point(6, 6);
- newImage = ImageHelper.CreateShadow((Bitmap)Image, 1f, 7, offset, PixelFormat.Format24bppRgb); //Image.PixelFormat);
+ newImage = ImageHelper.CreateShadow((Bitmap)Image, 1f, 9, ref offset, PixelFormat.Format32bppArgb); //Image.PixelFormat);
break;
case Effects.TornEdge:
- offset = new Point(5, 5);
using (Bitmap tmpImage = ImageHelper.CreateTornEdge((Bitmap)Image)) {
- newImage = ImageHelper.CreateShadow(tmpImage, 1f, 6, offset, PixelFormat.Format24bppRgb); //Image.PixelFormat);
+ newImage = ImageHelper.CreateShadow(tmpImage, 1f, 6, ref offset, PixelFormat.Format32bppArgb); //Image.PixelFormat);
}
break;
case Effects.Border:
@@ -971,7 +969,7 @@ namespace Greenshot.Drawing {
// Draw a checkboard when capturing with transparency
protected override void OnPaintBackground(PaintEventArgs e) {
// check if we need to draw the checkerboard
- if (Image.PixelFormat == PixelFormat.Format32bppArgb && transparencyBackgroundBrush != null) {
+ if (Image.IsAlphaPixelFormat(Image.PixelFormat) && transparencyBackgroundBrush != null) {
Graphics targetGraphics = e.Graphics;
Rectangle clipRectangle = e.ClipRectangle;
targetGraphics.FillRectangle(transparencyBackgroundBrush, clipRectangle);
diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs
index 936a0bf47..e228756f9 100644
--- a/Greenshot/Forms/ImageEditorForm.cs
+++ b/Greenshot/Forms/ImageEditorForm.cs
@@ -1109,8 +1109,8 @@ namespace Greenshot {
if (capture!= null && capture.Image != null) {
bool addShadow = false;
if (addShadow) {
- Point offset = new Point(6, 6);
- using (Bitmap shadowImage = ImageHelper.CreateShadow(capture.Image, 1f, 7, offset, PixelFormat.Format32bppArgb)) {
+ Point offset = new Point(-1,-1);
+ using (Bitmap shadowImage = ImageHelper.CreateShadow(capture.Image, 1f, 7, ref offset, PixelFormat.Format32bppArgb)) {
surface.AddBitmapContainer(shadowImage, 100, 100);
}
} else {
diff --git a/GreenshotPlugin/Core/BitmapBuffer.cs b/GreenshotPlugin/Core/BitmapBuffer.cs
index 1580c2aec..4aa42ad37 100644
--- a/GreenshotPlugin/Core/BitmapBuffer.cs
+++ b/GreenshotPlugin/Core/BitmapBuffer.cs
@@ -422,6 +422,7 @@ namespace GreenshotPlugin.Core {
// aIndex is only set if the pixel format supports "A".
aIndex = -1;
switch(bitmap.PixelFormat) {
+ case PixelFormat.Format32bppPArgb:
case PixelFormat.Format32bppArgb:
bIndex = 0;
gIndex = 1;
diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs
index f52c5e297..395dae935 100644
--- a/GreenshotPlugin/Core/ImageHelper.cs
+++ b/GreenshotPlugin/Core/ImageHelper.cs
@@ -428,7 +428,7 @@ namespace GreenshotPlugin.Core {
}
byte[] nullColor = new byte[] { 255, 255, 255, 255 };
- if (sourceBitmap.PixelFormat == PixelFormat.Format32bppArgb) {
+ if (sourceBitmap.PixelFormat == PixelFormat.Format32bppArgb || sourceBitmap.PixelFormat == PixelFormat.Format32bppPArgb) {
nullColor = new byte[] { 0, 0, 0, 0 };
}
byte[] settingColor = new byte[4];
@@ -724,53 +724,51 @@ namespace GreenshotPlugin.Core {
/// What pixel format must the returning bitmap have
/// How many pixels is the original image moved?
/// Bitmap with the shadow, is bigger than the sourceBitmap!!
- public static Bitmap CreateShadow(Image sourceBitmap, float darkness, int shadowSize, Point offset, PixelFormat targetPixelformat) {
+ public static Bitmap CreateShadow(Image sourceBitmap, float darkness, int shadowSize, ref Point offset, PixelFormat targetPixelformat) {
// Create a new "clean" image
- Bitmap newImage = CreateEmpty(sourceBitmap.Width + (shadowSize * 2), sourceBitmap.Height + (shadowSize * 2), targetPixelformat, Color.Empty, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
+ Bitmap returnImage = null;
+ offset.X += shadowSize - 1;
+ offset.Y += shadowSize - 1;
+ using (Bitmap tmpImage = CreateEmpty(sourceBitmap.Width + (shadowSize * 2), sourceBitmap.Height + (shadowSize * 2), targetPixelformat, Color.Empty, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution)) {
+ using (Graphics graphics = Graphics.FromImage(tmpImage)) {
+ // Make sure we draw with the best quality!
+ graphics.SmoothingMode = SmoothingMode.HighQuality;
+ graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
+ graphics.CompositingQuality = CompositingQuality.HighQuality;
+ graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
- using (Graphics graphics = Graphics.FromImage(newImage)) {
- // Make sure we draw with the best quality!
- graphics.SmoothingMode = SmoothingMode.HighQuality;
- graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
- graphics.CompositingQuality = CompositingQuality.HighQuality;
- graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
-
- // Draw "shadow" offsetted
- ImageAttributes ia = new ImageAttributes();
- ColorMatrix cm = new ColorMatrix();
- cm.Matrix00 = 0;
- cm.Matrix11 = 0;
- cm.Matrix22 = 0;
- cm.Matrix33 = darkness;
- ia.SetColorMatrix(cm);
- Rectangle shadowRectangle = new Rectangle(new Point(shadowSize, shadowSize), sourceBitmap.Size);
- graphics.DrawImage(sourceBitmap, shadowRectangle, 0, 0, sourceBitmap.Width, sourceBitmap.Height, GraphicsUnit.Pixel, ia);
-
-
- // Only do the blur on the edges
- //Rectangle blurRectangle = new Rectangle(shadowSize + 30, shadowSize + 30, sourceBitmap.Width - 60, sourceBitmap.Height - 60);
- //Rectangle applyRect = ImageHelper.CreateIntersectRectangle(newImage.Size, blurRectangle, true);
- //LOG.DebugFormat("blurRect = {0} - applyRect = {1}", blurRectangle, applyRect);
- //using (Bitmap blurImage = ImageHelper.CreateBlur(newImage, applyRect, true, shadowSize, 1d, true, blurRectangle)) {
- // if (blurImage != null) {
- // graphics.DrawImageUnscaled(blurImage, applyRect.Location);
- // }
- //}
- // blur "shadow", apply to whole new image
- Rectangle newImageRectangle = new Rectangle(0, 0, newImage.Width, newImage.Height);
- //using (Bitmap blurImage = FastBlur(newImage, shadowSize-1)) {
- using (Bitmap blurImage = CreateBlur(newImage, newImageRectangle, true, shadowSize, 1d, false, newImageRectangle)) {
- graphics.DrawImageUnscaled(blurImage, newImageRectangle.Location);
+ // Draw "shadow" offsetted
+ ImageAttributes ia = new ImageAttributes();
+ ColorMatrix cm = new ColorMatrix();
+ cm.Matrix00 = 0;
+ cm.Matrix11 = 0;
+ cm.Matrix22 = 0;
+ cm.Matrix33 = darkness;
+ ia.SetColorMatrix(cm);
+ Rectangle shadowRectangle = new Rectangle(new Point(shadowSize - 1, shadowSize - 1), sourceBitmap.Size);
+ graphics.DrawImage(sourceBitmap, shadowRectangle, 0, 0, sourceBitmap.Width, sourceBitmap.Height, GraphicsUnit.Pixel, ia);
}
-
- // draw original with a TextureBrush so we have nice antialiasing!
- using (Brush textureBrush = new TextureBrush(sourceBitmap, WrapMode.Clamp)) {
- // We need to do a translate-tranform otherwise the image is wrapped
- graphics.TranslateTransform(offset.X, offset.Y);
- graphics.FillRectangle(textureBrush, 0, 0, sourceBitmap.Width, sourceBitmap.Height);
+ // blur "shadow", apply to whole new image
+ Rectangle newImageRectangle = new Rectangle(0, 0, tmpImage.Width, tmpImage.Height);
+ //using (Bitmap blurImage = FastBlur(newImage, shadowSize-1)) {
+ returnImage = CreateBlur(tmpImage, newImageRectangle, true, shadowSize, 1d, false, newImageRectangle);
+ }
+ if (returnImage != null) {
+ using (Graphics graphics = Graphics.FromImage(returnImage)) {
+ // Make sure we draw with the best quality!
+ graphics.SmoothingMode = SmoothingMode.HighQuality;
+ graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
+ graphics.CompositingQuality = CompositingQuality.HighQuality;
+ graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
+ // draw original with a TextureBrush so we have nice antialiasing!
+ using (Brush textureBrush = new TextureBrush(sourceBitmap, WrapMode.Clamp)) {
+ // We need to do a translate-tranform otherwise the image is wrapped
+ graphics.TranslateTransform(offset.X, offset.Y);
+ graphics.FillRectangle(textureBrush, 0, 0, sourceBitmap.Width, sourceBitmap.Height);
+ }
}
}
- return newImage;
+ return returnImage;
}
///
@@ -883,6 +881,7 @@ namespace GreenshotPlugin.Core {
/// bool if we support it
public static bool SupportsPixelFormat(PixelFormat pixelformat) {
return (pixelformat.Equals(PixelFormat.Format32bppArgb) ||
+ pixelformat.Equals(PixelFormat.Format32bppPArgb) ||
pixelformat.Equals(PixelFormat.Format32bppRgb) ||
pixelformat.Equals(PixelFormat.Format24bppRgb));
}