mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-04 04:06:05 +13:00
Workaround for image resize bug
Not using animate window in toast window
This commit is contained in:
parent
8d81b6df67
commit
4b719fee96
4 changed files with 23 additions and 27 deletions
|
@ -84,11 +84,20 @@ public static Image ResizeImage(Image img, int width, int height)
|
||||||
Bitmap bmp = new Bitmap(width, height, img.PixelFormat);
|
Bitmap bmp = new Bitmap(width, height, img.PixelFormat);
|
||||||
bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution);
|
bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution);
|
||||||
|
|
||||||
using (Graphics g = Graphics.FromImage(bmp))
|
|
||||||
using (img)
|
using (img)
|
||||||
|
using (Graphics g = Graphics.FromImage(bmp))
|
||||||
{
|
{
|
||||||
g.SetHighQuality();
|
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
g.DrawImage(img, 0, 0, width, height);
|
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;
|
return bmp;
|
||||||
|
|
1
ShareX/Forms/NotificationForm.Designer.cs
generated
1
ShareX/Forms/NotificationForm.Designer.cs
generated
|
@ -47,7 +47,6 @@ private void InitializeComponent()
|
||||||
this.ShowInTaskbar = false;
|
this.ShowInTaskbar = false;
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
|
||||||
this.Text = "ToastForm";
|
this.Text = "ToastForm";
|
||||||
this.TopMost = true;
|
|
||||||
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.NotificationForm_MouseClick);
|
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.NotificationForm_MouseClick);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
|
|
@ -45,13 +45,10 @@ public partial class NotificationForm : Form
|
||||||
public string URL { get; private set; }
|
public string URL { get; private set; }
|
||||||
|
|
||||||
private int windowOffset = 3;
|
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();
|
InitializeComponent();
|
||||||
maxImageSize = size;
|
|
||||||
ToastText = text;
|
|
||||||
|
|
||||||
img = ImageHelpers.ResizeImageLimit(img, size);
|
img = ImageHelpers.ResizeImageLimit(img, size);
|
||||||
img = ImageHelpers.DrawCheckers(img);
|
img = ImageHelpers.DrawCheckers(img);
|
||||||
|
@ -59,12 +56,9 @@ public NotificationForm(int duration, Size size, string text, Image img, string
|
||||||
URL = url;
|
URL = url;
|
||||||
|
|
||||||
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
|
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.Interval = duration;
|
||||||
tDuration.Start();
|
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)
|
private void tDuration_Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
tDuration.Stop();
|
tDuration.Stop();
|
||||||
NativeMethods.AnimateWindow(Handle, 1000, AnimateWindowFlags.AW_HIDE | AnimateWindowFlags.AW_BLEND);
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,26 +88,21 @@ protected override void OnPaint(PaintEventArgs e)
|
||||||
g.DrawRectangleProper(Pens.Black, e.ClipRectangle);
|
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))
|
if (!string.IsNullOrEmpty(imagePath) && File.Exists(imagePath))
|
||||||
{
|
{
|
||||||
Thread thread = new Thread(() =>
|
Image img = ImageHelpers.LoadImage(imagePath);
|
||||||
{
|
NotificationForm form = new NotificationForm(5000, new Size(400, 300), img, url);
|
||||||
using (Image img = ImageHelpers.LoadImage(imagePath))
|
NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate);
|
||||||
using (NotificationForm toastForm = new NotificationForm(5000, new Size(400, 300), text, img, url))
|
NativeMethods.SetWindowPos(form.Handle, (IntPtr)SpecialWindowHandles.HWND_TOP, 0, 0, 0, 0,
|
||||||
{
|
SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE);
|
||||||
toastForm.ShowDialog();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
thread.Start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NotificationForm_MouseClick(object sender, MouseEventArgs e)
|
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))
|
if (!string.IsNullOrEmpty(URL))
|
||||||
{
|
{
|
||||||
|
|
|
@ -324,7 +324,7 @@ private static void task_UploadCompleted(UploadTask task)
|
||||||
|
|
||||||
if (task.Info.TaskSettings.GeneralSettings.ShowToastWindowAfterTask)
|
if (task.Info.TaskSettings.GeneralSettings.ShowToastWindowAfterTask)
|
||||||
{
|
{
|
||||||
NotificationForm.ShowAsync(balloonTipText, info.FilePath, result);
|
NotificationForm.Show(info.FilePath, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue