2013-11-03 23:53:49 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2020-02-05 20:19:48 +13:00
|
|
|
|
Copyright (c) 2007-2020 ShareX Team
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.HelpersLib
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-02-26 09:55:54 +13:00
|
|
|
|
public class ImageViewer : Form
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2020-11-27 02:39:30 +13:00
|
|
|
|
private Image image;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2020-11-27 02:39:30 +13:00
|
|
|
|
private ImageViewer(Image img)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2020-11-27 02:39:30 +13:00
|
|
|
|
image = img;
|
2019-05-17 11:01:37 +12:00
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
InitializeComponent();
|
2019-07-06 18:58:22 +12:00
|
|
|
|
ShareXResources.ApplyTheme(this);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ShowImage(Image img)
|
|
|
|
|
{
|
|
|
|
|
if (img != null)
|
|
|
|
|
{
|
2020-11-27 02:39:30 +13:00
|
|
|
|
using (Image tempImage = img.CloneSafe())
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2020-11-27 02:39:30 +13:00
|
|
|
|
if (tempImage != null)
|
|
|
|
|
{
|
|
|
|
|
using (ImageViewer viewer = new ImageViewer(tempImage))
|
|
|
|
|
{
|
|
|
|
|
viewer.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-22 22:21:26 +13:00
|
|
|
|
public static void ShowImage(string filePath)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2020-03-22 12:22:43 +13:00
|
|
|
|
using (Bitmap bmp = ImageHelpers.LoadImage(filePath))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2020-03-22 12:22:43 +13:00
|
|
|
|
if (bmp != null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2020-03-22 12:22:43 +13:00
|
|
|
|
using (ImageViewer viewer = new ImageViewer(bmp))
|
2019-11-22 22:21:26 +13:00
|
|
|
|
{
|
|
|
|
|
viewer.ShowDialog();
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowScreenshot_Shown(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-03-10 05:37:54 +13:00
|
|
|
|
this.ForceActivate();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowScreenshot_Deactivate(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void pbPreview_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void pbPreview_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode == Keys.Escape || e.KeyCode == Keys.Enter || e.KeyCode == Keys.Space)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Windows Form Designer generated code
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Required designer variable.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private System.ComponentModel.IContainer components = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clean up any resources being used.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (disposing && (components != null))
|
|
|
|
|
{
|
|
|
|
|
components.Dispose();
|
2015-06-28 02:01:22 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2020-11-27 02:39:30 +13:00
|
|
|
|
if (image != null)
|
2015-06-28 02:01:22 +12:00
|
|
|
|
{
|
2020-11-27 02:39:30 +13:00
|
|
|
|
image.Dispose();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Required method for Designer support - do not modify
|
|
|
|
|
/// the contents of this method with the code editor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void InitializeComponent()
|
|
|
|
|
{
|
2018-10-10 00:30:22 +13:00
|
|
|
|
pbPreview = new MyPictureBox();
|
|
|
|
|
SuspendLayout();
|
|
|
|
|
|
|
|
|
|
BackColor = SystemColors.Window;
|
|
|
|
|
Bounds = CaptureHelpers.GetActiveScreenBounds();
|
|
|
|
|
DoubleBuffered = true;
|
|
|
|
|
FormBorderStyle = FormBorderStyle.None;
|
|
|
|
|
Text = "ShareX - Image viewer";
|
|
|
|
|
TopMost = true;
|
|
|
|
|
WindowState = FormWindowState.Normal;
|
|
|
|
|
StartPosition = FormStartPosition.Manual;
|
|
|
|
|
|
|
|
|
|
pbPreview.Cursor = Cursors.Hand;
|
2020-11-27 02:39:30 +13:00
|
|
|
|
pbPreview.Dock = DockStyle.Fill;
|
2018-10-10 00:30:22 +13:00
|
|
|
|
pbPreview.DrawCheckeredBackground = true;
|
|
|
|
|
pbPreview.FullscreenOnClick = false;
|
2020-11-27 02:39:30 +13:00
|
|
|
|
pbPreview.Location = new Point(0, 0);
|
2018-10-10 00:30:22 +13:00
|
|
|
|
pbPreview.Name = "pbPreview";
|
2019-07-06 18:58:22 +12:00
|
|
|
|
pbPreview.ShowImageSizeLabel = true;
|
2020-11-27 02:39:30 +13:00
|
|
|
|
pbPreview.Size = new Size(96, 100);
|
2018-10-10 00:30:22 +13:00
|
|
|
|
pbPreview.TabIndex = 0;
|
2020-11-27 02:39:30 +13:00
|
|
|
|
pbPreview.LoadImage(image);
|
2018-10-10 00:30:22 +13:00
|
|
|
|
Controls.Add(pbPreview);
|
|
|
|
|
|
2020-11-27 02:39:30 +13:00
|
|
|
|
Shown += new EventHandler(ShowScreenshot_Shown);
|
|
|
|
|
Deactivate += new EventHandler(ShowScreenshot_Deactivate);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
pbPreview.MouseDown += pbPreview_MouseDown;
|
|
|
|
|
pbPreview.KeyDown += pbPreview_KeyDown;
|
|
|
|
|
|
2018-10-10 00:30:22 +13:00
|
|
|
|
ResumeLayout(false);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MyPictureBox pbPreview;
|
|
|
|
|
|
|
|
|
|
#endregion Windows Form Designer generated code
|
|
|
|
|
}
|
|
|
|
|
}
|