Workaround for image resize bug

Not using animate window in toast window
This commit is contained in:
Jaex 2013-12-24 21:19:27 +02:00
parent 8d81b6df67
commit 4b719fee96
4 changed files with 23 additions and 27 deletions

View file

@ -84,11 +84,20 @@ public static Image ResizeImage(Image img, int width, int height)
Bitmap bmp = new Bitmap(width, height, img.PixelFormat);
bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution);
using (Graphics g = Graphics.FromImage(bmp))
using (img)
using (Graphics g = Graphics.FromImage(bmp))
{
g.SetHighQuality();
g.DrawImage(img, 0, 0, width, height);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.CompositingMode = CompositingMode.SourceOver;
using (ImageAttributes ia = new ImageAttributes())
{
ia.SetWrapMode(WrapMode.TileFlipXY);
g.DrawImage(img, new Rectangle(0, 0, width, height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
}
}
return bmp;

View file

@ -47,7 +47,6 @@ private void InitializeComponent()
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "ToastForm";
this.TopMost = true;
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.NotificationForm_MouseClick);
this.ResumeLayout(false);

View file

@ -45,13 +45,10 @@ public partial class NotificationForm : Form
public string URL { get; private set; }
private int windowOffset = 3;
private Size maxImageSize;
public NotificationForm(int duration, Size size, string text, Image img, string url)
public NotificationForm(int duration, Size size, Image img, string url)
{
InitializeComponent();
maxImageSize = size;
ToastText = text;
img = ImageHelpers.ResizeImageLimit(img, size);
img = ImageHelpers.DrawCheckers(img);
@ -59,12 +56,9 @@ public NotificationForm(int duration, Size size, string text, Image img, string
URL = url;
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
Size = new Size(img.Width + 2, img.Height + 2);
Location = new Point(Screen.PrimaryScreen.WorkingArea.Right - Width - windowOffset, Screen.PrimaryScreen.WorkingArea.Bottom - Height - windowOffset);
Rectangle rect = new Rectangle(Screen.PrimaryScreen.WorkingArea.Right - (img.Width + 2) - windowOffset,
Screen.PrimaryScreen.WorkingArea.Bottom - (img.Height + 2) - windowOffset, img.Width + 2, img.Height + 2);
NativeMethods.SetWindowPos(Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, rect.X, rect.Y, rect.Width, rect.Height, SetWindowPosFlags.SWP_NOACTIVATE);
NativeMethods.AnimateWindow(Handle, 500, AnimateWindowFlags.AW_SLIDE | AnimateWindowFlags.AW_VER_NEGATIVE);
tDuration.Interval = duration;
tDuration.Start();
}
@ -72,7 +66,6 @@ public NotificationForm(int duration, Size size, string text, Image img, string
private void tDuration_Tick(object sender, EventArgs e)
{
tDuration.Stop();
NativeMethods.AnimateWindow(Handle, 1000, AnimateWindowFlags.AW_HIDE | AnimateWindowFlags.AW_BLEND);
Close();
}
@ -95,26 +88,21 @@ protected override void OnPaint(PaintEventArgs e)
g.DrawRectangleProper(Pens.Black, e.ClipRectangle);
}
public static void ShowAsync(string text, string imagePath, string url)
public static void Show(string imagePath, string url)
{
if (!string.IsNullOrEmpty(imagePath) && File.Exists(imagePath))
{
Thread thread = new Thread(() =>
{
using (Image img = ImageHelpers.LoadImage(imagePath))
using (NotificationForm toastForm = new NotificationForm(5000, new Size(400, 300), text, img, url))
{
toastForm.ShowDialog();
}
});
thread.Start();
Image img = ImageHelpers.LoadImage(imagePath);
NotificationForm form = new NotificationForm(5000, new Size(400, 300), img, url);
NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate);
NativeMethods.SetWindowPos(form.Handle, (IntPtr)SpecialWindowHandles.HWND_TOP, 0, 0, 0, 0,
SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE);
}
}
private void NotificationForm_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
if (e.Button == MouseButtons.Left)
{
if (!string.IsNullOrEmpty(URL))
{

View file

@ -324,7 +324,7 @@ private static void task_UploadCompleted(UploadTask task)
if (task.Info.TaskSettings.GeneralSettings.ShowToastWindowAfterTask)
{
NotificationForm.ShowAsync(balloonTipText, info.FilePath, result);
NotificationForm.Show(info.FilePath, result);
}
}