2014-05-21 09:25:06 +12:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2016-01-04 04:16:01 +13:00
|
|
|
|
Copyright (c) 2007-2016 ShareX Team
|
2014-05-21 09:25:06 +12: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)
|
|
|
|
|
|
2014-06-01 14:05:59 +12:00
|
|
|
|
using Gma.QrCodeNet.Encoding;
|
|
|
|
|
using Gma.QrCodeNet.Encoding.Windows.Render;
|
2014-05-21 09:25:06 +12:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
2014-06-01 14:05:59 +12:00
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using System.IO;
|
2014-05-21 09:25:06 +12:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.HelpersLib
|
2014-05-21 09:25:06 +12:00
|
|
|
|
{
|
2015-09-01 06:36:50 +12:00
|
|
|
|
public partial class QRCodeForm : BaseForm
|
2014-05-21 09:25:06 +12:00
|
|
|
|
{
|
2014-07-19 09:38:30 +12:00
|
|
|
|
public bool EditMode { get; set; }
|
|
|
|
|
|
2014-05-21 10:46:06 +12:00
|
|
|
|
public QRCodeForm(string text = null)
|
2014-05-21 09:25:06 +12:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2014-05-21 09:49:31 +12:00
|
|
|
|
ClientSize = new Size(400, 400);
|
2014-05-21 10:46:06 +12:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(text))
|
|
|
|
|
{
|
|
|
|
|
qrMain.Dock = DockStyle.Fill;
|
|
|
|
|
qrMain.Cursor = Cursors.Hand;
|
2014-07-19 09:38:30 +12:00
|
|
|
|
Text += ": " + text;
|
2014-05-21 10:46:06 +12:00
|
|
|
|
qrMain.Text = text;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-07-19 09:38:30 +12:00
|
|
|
|
EditMode = true;
|
2014-05-21 10:46:06 +12:00
|
|
|
|
txtQRCode.Visible = true;
|
2016-01-16 18:47:57 +13:00
|
|
|
|
|
2016-01-16 15:12:21 +13:00
|
|
|
|
if (Clipboard.ContainsText())
|
|
|
|
|
{
|
|
|
|
|
text = Clipboard.GetText();
|
2016-01-16 18:47:57 +13:00
|
|
|
|
|
2016-01-16 15:12:21 +13:00
|
|
|
|
if (!string.IsNullOrEmpty(text) && URLHelpers.IsValidURLRegex(text))
|
|
|
|
|
{
|
|
|
|
|
txtQRCode.Text = text;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-01-16 18:47:57 +13:00
|
|
|
|
SetDefaultText();
|
2016-01-16 15:12:21 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-01-16 18:47:57 +13:00
|
|
|
|
SetDefaultText();
|
2016-01-16 15:12:21 +13:00
|
|
|
|
}
|
2016-01-16 18:47:57 +13:00
|
|
|
|
|
2014-05-21 10:46:06 +12:00
|
|
|
|
txtQRCode.SelectAll();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-16 18:47:57 +13:00
|
|
|
|
private void SetDefaultText()
|
2016-01-16 15:12:21 +13:00
|
|
|
|
{
|
|
|
|
|
txtQRCode.Text = "Input text to convert";
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 10:46:06 +12:00
|
|
|
|
private void txtQRCode_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
qrMain.Text = txtQRCode.Text;
|
2014-05-21 09:25:06 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void QRCodeForm_Resize(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
qrMain.Refresh();
|
|
|
|
|
}
|
2014-05-21 09:49:31 +12:00
|
|
|
|
|
|
|
|
|
private void qrMain_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-07-19 09:38:30 +12:00
|
|
|
|
if (!EditMode)
|
2014-05-21 10:46:06 +12:00
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2014-05-21 09:49:31 +12:00
|
|
|
|
}
|
2014-06-01 14:05:59 +12:00
|
|
|
|
|
|
|
|
|
private void tsmiCopy_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-10-31 11:27:20 +13:00
|
|
|
|
GraphicsRenderer gRender = new GraphicsRenderer(new FixedModuleSize(20, QuietZoneModules.Two));
|
2014-06-01 14:05:59 +12:00
|
|
|
|
BitMatrix matrix = qrMain.GetQrMatrix();
|
|
|
|
|
using (MemoryStream stream = new MemoryStream())
|
|
|
|
|
{
|
2014-10-31 11:27:20 +13:00
|
|
|
|
gRender.WriteToStream(matrix, ImageFormat.Png, stream);
|
|
|
|
|
|
2014-06-03 03:24:24 +12:00
|
|
|
|
using (Image img = Image.FromStream(stream))
|
|
|
|
|
{
|
|
|
|
|
ClipboardHelpers.CopyImage(img);
|
|
|
|
|
}
|
2014-06-01 14:05:59 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiSaveAs_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
|
|
|
|
|
{
|
2014-07-19 09:38:30 +12:00
|
|
|
|
saveFileDialog.Filter = @"PNG (*.png)|*.png|JPEG (*.jpg)|*.jpg|Bitmap (*.bmp)|*.bmp|Encapsuled PostScript (*.eps)|*.eps|SVG (*.svg)|*.svg";
|
2014-06-01 14:05:59 +12:00
|
|
|
|
saveFileDialog.FileName = txtQRCode.Text;
|
|
|
|
|
saveFileDialog.DefaultExt = "png";
|
|
|
|
|
|
2014-07-19 09:38:30 +12:00
|
|
|
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
2014-06-01 14:05:59 +12:00
|
|
|
|
{
|
2014-07-19 09:38:30 +12:00
|
|
|
|
string filePath = saveFileDialog.FileName;
|
2014-06-01 14:05:59 +12:00
|
|
|
|
|
2014-07-19 09:38:30 +12:00
|
|
|
|
if (filePath.EndsWith("eps"))
|
2014-06-01 14:05:59 +12:00
|
|
|
|
{
|
2014-07-19 09:38:30 +12:00
|
|
|
|
// Initialize the EPS renderer
|
|
|
|
|
EncapsulatedPostScriptRenderer renderer = new EncapsulatedPostScriptRenderer(new FixedModuleSize(6, QuietZoneModules.Two), // Modules size is 6/72th inch (72 points = 1 inch)
|
|
|
|
|
new FormColor(Color.Black), new FormColor(Color.White));
|
|
|
|
|
BitMatrix matrix = qrMain.GetQrMatrix();
|
|
|
|
|
using (FileStream fs = new FileStream(filePath, FileMode.Create))
|
|
|
|
|
{
|
|
|
|
|
renderer.WriteToStream(matrix, fs);
|
|
|
|
|
}
|
2014-06-01 14:05:59 +12:00
|
|
|
|
}
|
2014-07-19 09:38:30 +12:00
|
|
|
|
else if (filePath.EndsWith("svg"))
|
2014-06-01 14:05:59 +12:00
|
|
|
|
{
|
2014-07-19 09:38:30 +12:00
|
|
|
|
// Initialize the EPS renderer
|
|
|
|
|
SVGRenderer renderer = new SVGRenderer(new FixedModuleSize(6, QuietZoneModules.Two), // Modules size is 6/72th inch (72 points = 1 inch)
|
|
|
|
|
new FormColor(Color.FromArgb(150, 200, 200, 210)), new FormColor(Color.FromArgb(200, 255, 155, 0)));
|
|
|
|
|
BitMatrix matrix = qrMain.GetQrMatrix();
|
|
|
|
|
using (FileStream fs = new FileStream(filePath, FileMode.Create))
|
|
|
|
|
{
|
|
|
|
|
renderer.WriteToStream(matrix, fs, false);
|
|
|
|
|
}
|
2014-06-01 14:05:59 +12:00
|
|
|
|
}
|
2014-07-19 09:38:30 +12:00
|
|
|
|
else
|
2014-06-01 14:05:59 +12:00
|
|
|
|
{
|
2014-10-31 11:27:20 +13:00
|
|
|
|
GraphicsRenderer gRender = new GraphicsRenderer(new FixedModuleSize(20, QuietZoneModules.Two));
|
2014-07-19 09:38:30 +12:00
|
|
|
|
BitMatrix matrix = qrMain.GetQrMatrix();
|
|
|
|
|
using (FileStream fs = new FileStream(filePath, FileMode.Create))
|
|
|
|
|
{
|
2014-10-31 11:27:20 +13:00
|
|
|
|
gRender.WriteToStream(matrix, ImageHelpers.GetImageFormat(filePath), fs);
|
2014-07-19 09:38:30 +12:00
|
|
|
|
}
|
2014-06-01 14:05:59 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-21 09:25:06 +12:00
|
|
|
|
}
|
2016-01-16 18:47:57 +13:00
|
|
|
|
}
|