mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 09:33:46 -07:00
Refactoring: created a OutputSettings class to contain all the output settings for writing files. Default the settings are loaded from the configuration, in a later version it will be possible to have separate settings for every destination and these can be configured at one place... the settings form.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1815 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
5902a3d236
commit
e5fd88ebd3
21 changed files with 182 additions and 123 deletions
|
@ -152,6 +152,7 @@ namespace GreenshotOCR {
|
||||||
private const int MIN_HEIGHT = 130;
|
private const int MIN_HEIGHT = 130;
|
||||||
public static void DoOCR(ISurface surface) {
|
public static void DoOCR(ISurface surface) {
|
||||||
string filePath = null;
|
string filePath = null;
|
||||||
|
OutputSettings outputSettings = new OutputSettings(OutputFormat.bmp);
|
||||||
|
|
||||||
using (Image capturedImage = surface.GetImageForExport()) {
|
using (Image capturedImage = surface.GetImageForExport()) {
|
||||||
if (capturedImage.Width < MIN_WIDTH || capturedImage.Height < MIN_HEIGHT) {
|
if (capturedImage.Width < MIN_WIDTH || capturedImage.Height < MIN_HEIGHT) {
|
||||||
|
@ -163,10 +164,10 @@ namespace GreenshotOCR {
|
||||||
graphics.Clear(Color.White);
|
graphics.Clear(Color.White);
|
||||||
graphics.DrawImage(capturedImage, Point.Empty);
|
graphics.DrawImage(capturedImage, Point.Empty);
|
||||||
}
|
}
|
||||||
filePath = host.SaveToTmpFile(tmpImage, OutputFormat.bmp, 100, false);
|
filePath = host.SaveToTmpFile(tmpImage, outputSettings);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
filePath = host.SaveToTmpFile(capturedImage, OutputFormat.bmp, 100, false);
|
filePath = host.SaveToTmpFile(capturedImage, outputSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ namespace Greenshot.Configuration {
|
||||||
jpegqualitydialog_choosejpegquality,
|
jpegqualitydialog_choosejpegquality,
|
||||||
jpegqualitydialog_dontaskagain,
|
jpegqualitydialog_dontaskagain,
|
||||||
jpegqualitydialog_title,
|
jpegqualitydialog_title,
|
||||||
reduce_colors,
|
settings_reducecolors,
|
||||||
print_error,
|
print_error,
|
||||||
printoptions_allowcenter,
|
printoptions_allowcenter,
|
||||||
printoptions_allowenlarge,
|
printoptions_allowenlarge,
|
||||||
|
|
|
@ -188,7 +188,7 @@ namespace Greenshot.Destinations {
|
||||||
string tmpFile = captureDetails.Filename;
|
string tmpFile = captureDetails.Filename;
|
||||||
if (tmpFile == null || surface.Modified) {
|
if (tmpFile == null || surface.Modified) {
|
||||||
using (Image image = surface.GetImageForExport()) {
|
using (Image image = surface.GetImageForExport()) {
|
||||||
tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
|
tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, new OutputSettings());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.InfoFormat("Using already available file: {0}", tmpFile);
|
LOG.InfoFormat("Using already available file: {0}", tmpFile);
|
||||||
|
|
|
@ -113,7 +113,7 @@ namespace Greenshot.Destinations {
|
||||||
string tmpFile = captureDetails.Filename;
|
string tmpFile = captureDetails.Filename;
|
||||||
if (tmpFile == null || surface.Modified) {
|
if (tmpFile == null || surface.Modified) {
|
||||||
using (Image image = surface.GetImageForExport()) {
|
using (Image image = surface.GetImageForExport()) {
|
||||||
tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
|
tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, new OutputSettings());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (workbookName != null) {
|
if (workbookName != null) {
|
||||||
|
|
|
@ -115,7 +115,7 @@ namespace Greenshot.Destinations {
|
||||||
Size imageSize = Size.Empty;
|
Size imageSize = Size.Empty;
|
||||||
if (tmpFile == null || surface.Modified) {
|
if (tmpFile == null || surface.Modified) {
|
||||||
using (Image image = surface.GetImageForExport()) {
|
using (Image image = surface.GetImageForExport()) {
|
||||||
tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
|
tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, new OutputSettings());
|
||||||
imageSize = image.Size;
|
imageSize = image.Size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ namespace Greenshot.Destinations {
|
||||||
string tmpFile = captureDetails.Filename;
|
string tmpFile = captureDetails.Filename;
|
||||||
if (tmpFile == null || surface.Modified) {
|
if (tmpFile == null || surface.Modified) {
|
||||||
using (Image image = surface.GetImageForExport()) {
|
using (Image image = surface.GetImageForExport()) {
|
||||||
tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
|
tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, new OutputSettings());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (documentCaption != null) {
|
if (documentCaption != null) {
|
||||||
|
|
|
@ -451,9 +451,9 @@ namespace Greenshot {
|
||||||
get { return surface.CaptureDetails; }
|
get { return surface.CaptureDetails; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveToStream(Stream stream, OutputFormat extension, int quality, bool reduceColors) {
|
public void SaveToStream(Stream stream, OutputSettings outputSettings) {
|
||||||
using (Image image = surface.GetImageForExport()) {
|
using (Image image = surface.GetImageForExport()) {
|
||||||
ImageOutput.SaveToStream(image, stream, extension, quality, reduceColors);
|
ImageOutput.SaveToStream(image, stream, outputSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ using System.Windows.Forms;
|
||||||
using Greenshot.Configuration;
|
using Greenshot.Configuration;
|
||||||
using GreenshotPlugin.Core;
|
using GreenshotPlugin.Core;
|
||||||
using Greenshot.IniFile;
|
using Greenshot.IniFile;
|
||||||
|
using Greenshot.Plugin;
|
||||||
|
|
||||||
namespace Greenshot {
|
namespace Greenshot {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -30,31 +31,34 @@ namespace Greenshot {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class QualityDialog : Form {
|
public partial class QualityDialog : Form {
|
||||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
public int Quality = 0;
|
public OutputSettings Settings {
|
||||||
public bool ReduceColors = false;
|
get;
|
||||||
public QualityDialog(bool isJPG) {
|
set;
|
||||||
|
}
|
||||||
|
public QualityDialog(OutputSettings outputSettings) {
|
||||||
|
Settings = outputSettings;
|
||||||
//
|
//
|
||||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||||
//
|
//
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
|
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
|
||||||
|
|
||||||
this.checkBox_reduceColors.Checked = conf.OutputFileReduceColors;
|
this.checkBox_reduceColors.Checked = Settings.ReduceColors;
|
||||||
this.trackBarJpegQuality.Enabled = isJPG;
|
this.trackBarJpegQuality.Enabled = OutputFormat.jpg.Equals(outputSettings.Format);
|
||||||
this.trackBarJpegQuality.Value = conf.OutputFileJpegQuality;
|
this.trackBarJpegQuality.Value = Settings.JPGQuality;
|
||||||
this.textBoxJpegQuality.Enabled = isJPG;
|
this.textBoxJpegQuality.Enabled = OutputFormat.jpg.Equals(outputSettings.Format);
|
||||||
this.textBoxJpegQuality.Text = conf.OutputFileJpegQuality.ToString();
|
this.textBoxJpegQuality.Text = Settings.JPGQuality.ToString();
|
||||||
UpdateUI();
|
UpdateUI();
|
||||||
WindowDetails.ToForeground(Handle);
|
WindowDetails.ToForeground(Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button_okClick(object sender, System.EventArgs e) {
|
void Button_okClick(object sender, System.EventArgs e) {
|
||||||
Quality = this.trackBarJpegQuality.Value;
|
Settings.JPGQuality = this.trackBarJpegQuality.Value;
|
||||||
ReduceColors = checkBox_reduceColors.Checked;
|
Settings.ReduceColors = checkBox_reduceColors.Checked;
|
||||||
if(this.checkbox_dontaskagain.Checked) {
|
if (this.checkbox_dontaskagain.Checked) {
|
||||||
conf.OutputFileJpegQuality = Quality;
|
conf.OutputFileJpegQuality = Settings.JPGQuality;
|
||||||
conf.OutputFilePromptQuality = false;
|
conf.OutputFilePromptQuality = false;
|
||||||
conf.OutputFileReduceColors = ReduceColors;
|
conf.OutputFileReduceColors = Settings.ReduceColors;
|
||||||
IniConfig.Save();
|
IniConfig.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +67,7 @@ namespace Greenshot {
|
||||||
this.Text = Language.GetString(LangKey.jpegqualitydialog_title);
|
this.Text = Language.GetString(LangKey.jpegqualitydialog_title);
|
||||||
this.label_choosejpegquality.Text = Language.GetString(LangKey.jpegqualitydialog_choosejpegquality);
|
this.label_choosejpegquality.Text = Language.GetString(LangKey.jpegqualitydialog_choosejpegquality);
|
||||||
this.checkbox_dontaskagain.Text = Language.GetString(LangKey.jpegqualitydialog_dontaskagain);
|
this.checkbox_dontaskagain.Text = Language.GetString(LangKey.jpegqualitydialog_dontaskagain);
|
||||||
this.checkBox_reduceColors.Text = Language.GetString(LangKey.reduce_colors);
|
this.checkBox_reduceColors.Text = Language.GetString(LangKey.settings_reducecolors);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackBarJpegQualityScroll(object sender, System.EventArgs e) {
|
void TrackBarJpegQualityScroll(object sender, System.EventArgs e) {
|
||||||
|
|
74
Greenshot/Forms/SettingsForm.Designer.cs
generated
74
Greenshot/Forms/SettingsForm.Designer.cs
generated
|
@ -64,8 +64,8 @@ namespace Greenshot {
|
||||||
this.checkbox_copypathtoclipboard = new GreenshotPlugin.Controls.GreenshotCheckBox();
|
this.checkbox_copypathtoclipboard = new GreenshotPlugin.Controls.GreenshotCheckBox();
|
||||||
this.groupbox_applicationsettings = new GreenshotPlugin.Controls.GreenshotGroupBox();
|
this.groupbox_applicationsettings = new GreenshotPlugin.Controls.GreenshotGroupBox();
|
||||||
this.checkbox_autostartshortcut = new GreenshotPlugin.Controls.GreenshotCheckBox();
|
this.checkbox_autostartshortcut = new GreenshotPlugin.Controls.GreenshotCheckBox();
|
||||||
this.groupbox_jpegsettings = new GreenshotPlugin.Controls.GreenshotGroupBox();
|
this.groupbox_qualitysettings = new GreenshotPlugin.Controls.GreenshotGroupBox();
|
||||||
this.checkbox_alwaysshowjpegqualitydialog = new GreenshotPlugin.Controls.GreenshotCheckBox();
|
this.checkbox_alwaysshowqualitydialog = new GreenshotPlugin.Controls.GreenshotCheckBox();
|
||||||
this.label_jpegquality = new GreenshotPlugin.Controls.GreenshotLabel();
|
this.label_jpegquality = new GreenshotPlugin.Controls.GreenshotLabel();
|
||||||
this.textBoxJpegQuality = new System.Windows.Forms.TextBox();
|
this.textBoxJpegQuality = new System.Windows.Forms.TextBox();
|
||||||
this.trackBarJpegQuality = new System.Windows.Forms.TrackBar();
|
this.trackBarJpegQuality = new System.Windows.Forms.TrackBar();
|
||||||
|
@ -134,9 +134,10 @@ namespace Greenshot {
|
||||||
this.checkbox_enableexpert = new GreenshotPlugin.Controls.GreenshotCheckBox();
|
this.checkbox_enableexpert = new GreenshotPlugin.Controls.GreenshotCheckBox();
|
||||||
this.listview_clipboardformats = new System.Windows.Forms.ListView();
|
this.listview_clipboardformats = new System.Windows.Forms.ListView();
|
||||||
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||||
|
this.checkbox_reducecolors = new GreenshotPlugin.Controls.GreenshotCheckBox();
|
||||||
this.groupbox_preferredfilesettings.SuspendLayout();
|
this.groupbox_preferredfilesettings.SuspendLayout();
|
||||||
this.groupbox_applicationsettings.SuspendLayout();
|
this.groupbox_applicationsettings.SuspendLayout();
|
||||||
this.groupbox_jpegsettings.SuspendLayout();
|
this.groupbox_qualitysettings.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).BeginInit();
|
||||||
this.groupbox_destination.SuspendLayout();
|
this.groupbox_destination.SuspendLayout();
|
||||||
this.tabcontrol.SuspendLayout();
|
this.tabcontrol.SuspendLayout();
|
||||||
|
@ -164,9 +165,9 @@ namespace Greenshot {
|
||||||
//
|
//
|
||||||
this.textbox_storagelocation.Location = new System.Drawing.Point(138, 18);
|
this.textbox_storagelocation.Location = new System.Drawing.Point(138, 18);
|
||||||
this.textbox_storagelocation.Name = "textbox_storagelocation";
|
this.textbox_storagelocation.Name = "textbox_storagelocation";
|
||||||
|
this.textbox_storagelocation.PropertyName = "OutputFilePath";
|
||||||
this.textbox_storagelocation.Size = new System.Drawing.Size(233, 20);
|
this.textbox_storagelocation.Size = new System.Drawing.Size(233, 20);
|
||||||
this.textbox_storagelocation.TabIndex = 12;
|
this.textbox_storagelocation.TabIndex = 12;
|
||||||
this.textbox_storagelocation.PropertyName = "OutputFilePath";
|
|
||||||
//
|
//
|
||||||
// label_storagelocation
|
// label_storagelocation
|
||||||
//
|
//
|
||||||
|
@ -327,30 +328,31 @@ namespace Greenshot {
|
||||||
this.checkbox_autostartshortcut.Text = "Launch Greenshot on startup";
|
this.checkbox_autostartshortcut.Text = "Launch Greenshot on startup";
|
||||||
this.checkbox_autostartshortcut.UseVisualStyleBackColor = true;
|
this.checkbox_autostartshortcut.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// groupbox_jpegsettings
|
// groupbox_qualitysettings
|
||||||
//
|
//
|
||||||
this.groupbox_jpegsettings.Controls.Add(this.checkbox_alwaysshowjpegqualitydialog);
|
this.groupbox_qualitysettings.Controls.Add(this.checkbox_reducecolors);
|
||||||
this.groupbox_jpegsettings.Controls.Add(this.label_jpegquality);
|
this.groupbox_qualitysettings.Controls.Add(this.checkbox_alwaysshowqualitydialog);
|
||||||
this.groupbox_jpegsettings.Controls.Add(this.textBoxJpegQuality);
|
this.groupbox_qualitysettings.Controls.Add(this.label_jpegquality);
|
||||||
this.groupbox_jpegsettings.Controls.Add(this.trackBarJpegQuality);
|
this.groupbox_qualitysettings.Controls.Add(this.textBoxJpegQuality);
|
||||||
this.groupbox_jpegsettings.LanguageKey = "settings_jpegsettings";
|
this.groupbox_qualitysettings.Controls.Add(this.trackBarJpegQuality);
|
||||||
this.groupbox_jpegsettings.Location = new System.Drawing.Point(2, 156);
|
this.groupbox_qualitysettings.LanguageKey = "settings_jpegsettings";
|
||||||
this.groupbox_jpegsettings.Name = "groupbox_jpegsettings";
|
this.groupbox_qualitysettings.Location = new System.Drawing.Point(2, 156);
|
||||||
this.groupbox_jpegsettings.Size = new System.Drawing.Size(412, 83);
|
this.groupbox_qualitysettings.Name = "groupbox_qualitysettings";
|
||||||
this.groupbox_jpegsettings.TabIndex = 14;
|
this.groupbox_qualitysettings.Size = new System.Drawing.Size(412, 106);
|
||||||
this.groupbox_jpegsettings.TabStop = false;
|
this.groupbox_qualitysettings.TabIndex = 14;
|
||||||
this.groupbox_jpegsettings.Text = "JPEG settings";
|
this.groupbox_qualitysettings.TabStop = false;
|
||||||
|
this.groupbox_qualitysettings.Text = "JPEG settings";
|
||||||
//
|
//
|
||||||
// checkbox_alwaysshowjpegqualitydialog
|
// checkbox_alwaysshowqualitydialog
|
||||||
//
|
//
|
||||||
this.checkbox_alwaysshowjpegqualitydialog.LanguageKey = "settings_alwaysshowjpegqualitydialog";
|
this.checkbox_alwaysshowqualitydialog.LanguageKey = "settings_alwaysshowjpegqualitydialog";
|
||||||
this.checkbox_alwaysshowjpegqualitydialog.Location = new System.Drawing.Point(12, 50);
|
this.checkbox_alwaysshowqualitydialog.Location = new System.Drawing.Point(12, 50);
|
||||||
this.checkbox_alwaysshowjpegqualitydialog.Name = "checkbox_alwaysshowjpegqualitydialog";
|
this.checkbox_alwaysshowqualitydialog.Name = "checkbox_alwaysshowqualitydialog";
|
||||||
this.checkbox_alwaysshowjpegqualitydialog.PropertyName = "OutputFilePromptQuality";
|
this.checkbox_alwaysshowqualitydialog.PropertyName = "OutputFilePromptQuality";
|
||||||
this.checkbox_alwaysshowjpegqualitydialog.Size = new System.Drawing.Size(394, 25);
|
this.checkbox_alwaysshowqualitydialog.Size = new System.Drawing.Size(394, 25);
|
||||||
this.checkbox_alwaysshowjpegqualitydialog.TabIndex = 16;
|
this.checkbox_alwaysshowqualitydialog.TabIndex = 16;
|
||||||
this.checkbox_alwaysshowjpegqualitydialog.Text = "Show JPEG quality dialog every time a JPEG image is saved";
|
this.checkbox_alwaysshowqualitydialog.Text = "Show quality dialog every time a JPEG image is saved";
|
||||||
this.checkbox_alwaysshowjpegqualitydialog.UseVisualStyleBackColor = true;
|
this.checkbox_alwaysshowqualitydialog.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// label_jpegquality
|
// label_jpegquality
|
||||||
//
|
//
|
||||||
|
@ -800,7 +802,7 @@ namespace Greenshot {
|
||||||
//
|
//
|
||||||
this.tab_output.BackColor = System.Drawing.Color.Transparent;
|
this.tab_output.BackColor = System.Drawing.Color.Transparent;
|
||||||
this.tab_output.Controls.Add(this.groupbox_preferredfilesettings);
|
this.tab_output.Controls.Add(this.groupbox_preferredfilesettings);
|
||||||
this.tab_output.Controls.Add(this.groupbox_jpegsettings);
|
this.tab_output.Controls.Add(this.groupbox_qualitysettings);
|
||||||
this.tab_output.LanguageKey = "settings_output";
|
this.tab_output.LanguageKey = "settings_output";
|
||||||
this.tab_output.Location = new System.Drawing.Point(4, 22);
|
this.tab_output.Location = new System.Drawing.Point(4, 22);
|
||||||
this.tab_output.Name = "tab_output";
|
this.tab_output.Name = "tab_output";
|
||||||
|
@ -1155,6 +1157,17 @@ namespace Greenshot {
|
||||||
this.columnHeader1.Text = "Destination";
|
this.columnHeader1.Text = "Destination";
|
||||||
this.columnHeader1.Width = 280;
|
this.columnHeader1.Width = 280;
|
||||||
//
|
//
|
||||||
|
// checkbox_reducecolors
|
||||||
|
//
|
||||||
|
this.checkbox_reducecolors.LanguageKey = "settings_reducecolors";
|
||||||
|
this.checkbox_reducecolors.Location = new System.Drawing.Point(12, 72);
|
||||||
|
this.checkbox_reducecolors.Name = "checkbox_reducecolors";
|
||||||
|
this.checkbox_reducecolors.PropertyName = "OutputFileReduceColors";
|
||||||
|
this.checkbox_reducecolors.Size = new System.Drawing.Size(394, 25);
|
||||||
|
this.checkbox_reducecolors.TabIndex = 17;
|
||||||
|
this.checkbox_reducecolors.Text = "Show quality dialog every time a JPEG image is saved";
|
||||||
|
this.checkbox_reducecolors.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
// SettingsForm
|
// SettingsForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
|
||||||
|
@ -1174,8 +1187,8 @@ namespace Greenshot {
|
||||||
this.groupbox_preferredfilesettings.ResumeLayout(false);
|
this.groupbox_preferredfilesettings.ResumeLayout(false);
|
||||||
this.groupbox_preferredfilesettings.PerformLayout();
|
this.groupbox_preferredfilesettings.PerformLayout();
|
||||||
this.groupbox_applicationsettings.ResumeLayout(false);
|
this.groupbox_applicationsettings.ResumeLayout(false);
|
||||||
this.groupbox_jpegsettings.ResumeLayout(false);
|
this.groupbox_qualitysettings.ResumeLayout(false);
|
||||||
this.groupbox_jpegsettings.PerformLayout();
|
this.groupbox_qualitysettings.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).EndInit();
|
||||||
this.groupbox_destination.ResumeLayout(false);
|
this.groupbox_destination.ResumeLayout(false);
|
||||||
this.tabcontrol.ResumeLayout(false);
|
this.tabcontrol.ResumeLayout(false);
|
||||||
|
@ -1256,11 +1269,11 @@ namespace Greenshot {
|
||||||
private System.Windows.Forms.TabControl tabcontrol;
|
private System.Windows.Forms.TabControl tabcontrol;
|
||||||
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_autostartshortcut;
|
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_autostartshortcut;
|
||||||
private GreenshotPlugin.Controls.GreenshotGroupBox groupbox_destination;
|
private GreenshotPlugin.Controls.GreenshotGroupBox groupbox_destination;
|
||||||
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_alwaysshowjpegqualitydialog;
|
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_alwaysshowqualitydialog;
|
||||||
private System.Windows.Forms.TextBox textBoxJpegQuality;
|
private System.Windows.Forms.TextBox textBoxJpegQuality;
|
||||||
private GreenshotPlugin.Controls.GreenshotLabel label_jpegquality;
|
private GreenshotPlugin.Controls.GreenshotLabel label_jpegquality;
|
||||||
private System.Windows.Forms.TrackBar trackBarJpegQuality;
|
private System.Windows.Forms.TrackBar trackBarJpegQuality;
|
||||||
private GreenshotPlugin.Controls.GreenshotGroupBox groupbox_jpegsettings;
|
private GreenshotPlugin.Controls.GreenshotGroupBox groupbox_qualitysettings;
|
||||||
private GreenshotPlugin.Controls.GreenshotGroupBox groupbox_applicationsettings;
|
private GreenshotPlugin.Controls.GreenshotGroupBox groupbox_applicationsettings;
|
||||||
private GreenshotPlugin.Controls.GreenshotGroupBox groupbox_preferredfilesettings;
|
private GreenshotPlugin.Controls.GreenshotGroupBox groupbox_preferredfilesettings;
|
||||||
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_playsound;
|
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_playsound;
|
||||||
|
@ -1291,5 +1304,6 @@ namespace Greenshot {
|
||||||
private GreenshotPlugin.Controls.GreenshotTextBox textbox_footerpattern;
|
private GreenshotPlugin.Controls.GreenshotTextBox textbox_footerpattern;
|
||||||
private GreenshotPlugin.Controls.GreenshotLabel label_counter;
|
private GreenshotPlugin.Controls.GreenshotLabel label_counter;
|
||||||
private GreenshotPlugin.Controls.GreenshotTextBox textbox_counter;
|
private GreenshotPlugin.Controls.GreenshotTextBox textbox_counter;
|
||||||
|
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_reducecolors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ using Greenshot.Configuration;
|
||||||
using GreenshotPlugin.UnmanagedHelpers;
|
using GreenshotPlugin.UnmanagedHelpers;
|
||||||
using GreenshotPlugin.Core;
|
using GreenshotPlugin.Core;
|
||||||
using Greenshot.IniFile;
|
using Greenshot.IniFile;
|
||||||
|
using Greenshot.Plugin;
|
||||||
|
|
||||||
namespace Greenshot.Helpers {
|
namespace Greenshot.Helpers {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -380,7 +381,7 @@ EndSelection:<<<<<<<4
|
||||||
|
|
||||||
// Set the HTML
|
// Set the HTML
|
||||||
if (config.ClipboardFormats.Contains(ClipboardFormat.HTML)) {
|
if (config.ClipboardFormats.Contains(ClipboardFormat.HTML)) {
|
||||||
string tmpFile = ImageOutput.SaveToTmpFile(image, OutputFormat.png, config.OutputFileJpegQuality, config.OutputFileReduceColors);
|
string tmpFile = ImageOutput.SaveToTmpFile(image, new OutputSettings(OutputFormat.png));
|
||||||
string html = getHTMLString(image, tmpFile);
|
string html = getHTMLString(image, tmpFile);
|
||||||
ido.SetText(html, TextDataFormat.Html);
|
ido.SetText(html, TextDataFormat.Html);
|
||||||
} else if (config.ClipboardFormats.Contains(ClipboardFormat.HTMLDATAURL)) {
|
} else if (config.ClipboardFormats.Contains(ClipboardFormat.HTMLDATAURL)) {
|
||||||
|
|
|
@ -75,11 +75,11 @@ namespace Greenshot.Helpers {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves image to stream with specified quality
|
/// Saves image to stream with specified quality
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void SaveToStream(Image imageToSave, Stream stream, OutputFormat extension, int quality, bool reduceColors) {
|
public static void SaveToStream(Image imageToSave, Stream stream, OutputSettings outputSettings) {
|
||||||
ImageFormat imageFormat = null;
|
ImageFormat imageFormat = null;
|
||||||
bool disposeImage = false;
|
bool disposeImage = false;
|
||||||
|
|
||||||
switch (extension) {
|
switch (outputSettings.Format) {
|
||||||
case OutputFormat.bmp:
|
case OutputFormat.bmp:
|
||||||
imageFormat = ImageFormat.Bmp;
|
imageFormat = ImageFormat.Bmp;
|
||||||
break;
|
break;
|
||||||
|
@ -100,11 +100,6 @@ namespace Greenshot.Helpers {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix for Bug #3468436, force quantizing when output format is gif as this has only 256 colors!
|
|
||||||
if (ImageFormat.Gif.Equals(imageFormat)) {
|
|
||||||
reduceColors = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removing transparency if it's not supported
|
// Removing transparency if it's not supported
|
||||||
if (imageFormat != ImageFormat.Png) {
|
if (imageFormat != ImageFormat.Png) {
|
||||||
imageToSave = ImageHelper.Clone(imageToSave, PixelFormat.Format24bppRgb);
|
imageToSave = ImageHelper.Clone(imageToSave, PixelFormat.Format24bppRgb);
|
||||||
|
@ -112,11 +107,11 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for color reduction, forced or automatically
|
// check for color reduction, forced or automatically
|
||||||
if (conf.OutputFileAutoReduceColors || reduceColors) {
|
if (conf.OutputFileAutoReduceColors || outputSettings.ReduceColors) {
|
||||||
WuQuantizer quantizer = new WuQuantizer((Bitmap)imageToSave);
|
WuQuantizer quantizer = new WuQuantizer((Bitmap)imageToSave);
|
||||||
int colorCount = quantizer.GetColorCount();
|
int colorCount = quantizer.GetColorCount();
|
||||||
LOG.InfoFormat("Image with format {0} has {1} colors", imageToSave.PixelFormat, colorCount);
|
LOG.InfoFormat("Image with format {0} has {1} colors", imageToSave.PixelFormat, colorCount);
|
||||||
if (reduceColors || colorCount < 256) {
|
if (outputSettings.ReduceColors || colorCount < 256) {
|
||||||
try {
|
try {
|
||||||
LOG.Info("Reducing colors on bitmap to 255.");
|
LOG.Info("Reducing colors on bitmap to 255.");
|
||||||
Image tmpImage = quantizer.GetQuantizedImage(255);
|
Image tmpImage = quantizer.GetQuantizedImage(255);
|
||||||
|
@ -147,7 +142,7 @@ namespace Greenshot.Helpers {
|
||||||
LOG.DebugFormat("Saving image to stream with Format {0} and PixelFormat {1}", imageFormat, imageToSave.PixelFormat);
|
LOG.DebugFormat("Saving image to stream with Format {0} and PixelFormat {1}", imageFormat, imageToSave.PixelFormat);
|
||||||
if (imageFormat == ImageFormat.Jpeg) {
|
if (imageFormat == ImageFormat.Jpeg) {
|
||||||
EncoderParameters parameters = new EncoderParameters(1);
|
EncoderParameters parameters = new EncoderParameters(1);
|
||||||
parameters.Param[0] = new System.Drawing.Imaging.EncoderParameter(Encoder.Quality, quality);
|
parameters.Param[0] = new System.Drawing.Imaging.EncoderParameter(Encoder.Quality, outputSettings.JPGQuality);
|
||||||
ImageCodecInfo[] ies = ImageCodecInfo.GetImageEncoders();
|
ImageCodecInfo[] ies = ImageCodecInfo.GetImageEncoders();
|
||||||
imageToSave.Save(stream, ies[1], parameters);
|
imageToSave.Save(stream, ies[1], parameters);
|
||||||
} else if (imageFormat != ImageFormat.Png && Image.IsAlphaPixelFormat(imageToSave.PixelFormat)) {
|
} else if (imageFormat != ImageFormat.Png && Image.IsAlphaPixelFormat(imageToSave.PixelFormat)) {
|
||||||
|
@ -169,7 +164,7 @@ namespace Greenshot.Helpers {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves image to specific path with specified quality
|
/// Saves image to specific path with specified quality
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Save(Image image, string fullPath, bool allowOverwrite, int quality, bool reduceColors, bool copyPathToClipboard) {
|
public static void Save(Image image, string fullPath, bool allowOverwrite, OutputSettings outputSettings, bool copyPathToClipboard) {
|
||||||
fullPath = FilenameHelper.MakeFQFilenameSafe(fullPath);
|
fullPath = FilenameHelper.MakeFQFilenameSafe(fullPath);
|
||||||
string path = Path.GetDirectoryName(fullPath);
|
string path = Path.GetDirectoryName(fullPath);
|
||||||
|
|
||||||
|
@ -198,7 +193,7 @@ namespace Greenshot.Helpers {
|
||||||
LOG.DebugFormat("Saving image to {0}", fullPath);
|
LOG.DebugFormat("Saving image to {0}", fullPath);
|
||||||
// Create the stream and call SaveToStream
|
// Create the stream and call SaveToStream
|
||||||
using (FileStream stream = new FileStream(fullPath, FileMode.Create, FileAccess.Write)) {
|
using (FileStream stream = new FileStream(fullPath, FileMode.Create, FileAccess.Write)) {
|
||||||
SaveToStream(image, stream, format, quality, reduceColors);
|
SaveToStream(image, stream, outputSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copyPathToClipboard) {
|
if (copyPathToClipboard) {
|
||||||
|
@ -213,26 +208,23 @@ namespace Greenshot.Helpers {
|
||||||
/// <param name="fullPath">the absolute destination path including file name</param>
|
/// <param name="fullPath">the absolute destination path including file name</param>
|
||||||
/// <param name="allowOverwrite">true if overwrite is allowed, false if not</param>
|
/// <param name="allowOverwrite">true if overwrite is allowed, false if not</param>
|
||||||
public static void Save(Image img, string fullPath, bool allowOverwrite) {
|
public static void Save(Image img, string fullPath, bool allowOverwrite) {
|
||||||
int quality;
|
|
||||||
bool reduceColors = false;
|
|
||||||
|
|
||||||
// Fix for bug 2912959
|
// Fix for bug 2912959
|
||||||
string extension = fullPath.Substring(fullPath.LastIndexOf(".") + 1);
|
string extension = fullPath.Substring(fullPath.LastIndexOf(".") + 1);
|
||||||
bool isJPG = false;
|
OutputFormat format = OutputFormat.png;
|
||||||
|
try {
|
||||||
if (extension != null) {
|
if (extension != null) {
|
||||||
isJPG = "JPG".Equals(extension.ToUpper()) || "JPEG".Equals(extension.ToUpper());
|
format = (OutputFormat)Enum.Parse(typeof(OutputFormat), extension.ToLower());
|
||||||
}
|
}
|
||||||
|
} catch (ArgumentException ae) {
|
||||||
if(conf.OutputFilePromptQuality) {
|
LOG.Warn("Couldn't parse extension: " + extension, ae);
|
||||||
QualityDialog qualityDialog = new QualityDialog(isJPG);
|
}
|
||||||
|
// Get output settings from the configuration
|
||||||
|
OutputSettings outputSettings = new OutputSettings(format);
|
||||||
|
if (conf.OutputFilePromptQuality) {
|
||||||
|
QualityDialog qualityDialog = new QualityDialog(outputSettings);
|
||||||
qualityDialog.ShowDialog();
|
qualityDialog.ShowDialog();
|
||||||
quality = qualityDialog.Quality;
|
|
||||||
reduceColors = qualityDialog.ReduceColors;
|
|
||||||
} else {
|
|
||||||
quality = conf.OutputFileJpegQuality;
|
|
||||||
reduceColors = conf.OutputFileReduceColors;
|
|
||||||
}
|
}
|
||||||
Save(img, fullPath, allowOverwrite, quality, reduceColors, conf.OutputFileCopyPathToClipboard);
|
Save(img, fullPath, allowOverwrite, outputSettings, conf.OutputFileCopyPathToClipboard);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -261,12 +253,12 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public static string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputFormat outputFormat, int quality, bool reduceColors) {
|
public static string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputSettings outputSettings) {
|
||||||
string pattern = conf.OutputFileFilenamePattern;
|
string pattern = conf.OutputFileFilenamePattern;
|
||||||
if (pattern == null || string.IsNullOrEmpty(pattern.Trim())) {
|
if (pattern == null || string.IsNullOrEmpty(pattern.Trim())) {
|
||||||
pattern = "greenshot ${capturetime}";
|
pattern = "greenshot ${capturetime}";
|
||||||
}
|
}
|
||||||
string filename = FilenameHelper.GetFilenameFromPattern(pattern, outputFormat, captureDetails);
|
string filename = FilenameHelper.GetFilenameFromPattern(pattern, outputSettings.Format, captureDetails);
|
||||||
// Prevent problems with "other characters", which causes a problem in e.g. Outlook 2007 or break our HTML
|
// Prevent problems with "other characters", which causes a problem in e.g. Outlook 2007 or break our HTML
|
||||||
filename = Regex.Replace(filename, @"[^\d\w\.]", "_");
|
filename = Regex.Replace(filename, @"[^\d\w\.]", "_");
|
||||||
// Remove multiple "_"
|
// Remove multiple "_"
|
||||||
|
@ -278,7 +270,7 @@ namespace Greenshot.Helpers {
|
||||||
// Catching any exception to prevent that the user can't write in the directory.
|
// Catching any exception to prevent that the user can't write in the directory.
|
||||||
// This is done for e.g. bugs #2974608, #2963943, #2816163, #2795317, #2789218
|
// This is done for e.g. bugs #2974608, #2963943, #2816163, #2795317, #2789218
|
||||||
try {
|
try {
|
||||||
ImageOutput.Save(image, tmpFile, true, quality, reduceColors, false);
|
ImageOutput.Save(image, tmpFile, true, outputSettings, false);
|
||||||
tmpFileCache.Add(tmpFile, tmpFile);
|
tmpFileCache.Add(tmpFile, tmpFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Show the problem
|
// Show the problem
|
||||||
|
@ -294,15 +286,15 @@ namespace Greenshot.Helpers {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="image"></param>
|
/// <param name="image"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string SaveToTmpFile(Image image, OutputFormat outputFormat, int quality, bool reduceColors) {
|
public static string SaveToTmpFile(Image image, OutputSettings outputSettings) {
|
||||||
string tmpFile = Path.GetRandomFileName() + "." + outputFormat.ToString();
|
string tmpFile = Path.GetRandomFileName() + "." + outputSettings.Format.ToString();
|
||||||
// Prevent problems with "other characters", which could cause problems
|
// Prevent problems with "other characters", which could cause problems
|
||||||
tmpFile = Regex.Replace(tmpFile, @"[^\d\w\.]", "");
|
tmpFile = Regex.Replace(tmpFile, @"[^\d\w\.]", "");
|
||||||
string tmpPath = Path.Combine(Path.GetTempPath(), tmpFile);
|
string tmpPath = Path.Combine(Path.GetTempPath(), tmpFile);
|
||||||
LOG.Debug("Creating TMP File : " + tmpPath);
|
LOG.Debug("Creating TMP File : " + tmpPath);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ImageOutput.Save(image, tmpPath, true, quality, reduceColors, false);
|
ImageOutput.Save(image, tmpPath, true, outputSettings, false);
|
||||||
tmpFileCache.Add(tmpPath, tmpPath);
|
tmpFileCache.Add(tmpPath, tmpPath);
|
||||||
} catch (Exception) {
|
} catch (Exception) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -66,7 +66,7 @@ namespace Greenshot.Helpers {
|
||||||
/// <param name="image">The image to send</param>
|
/// <param name="image">The image to send</param>
|
||||||
/// <param name="captureDetails">ICaptureDetails</param>
|
/// <param name="captureDetails">ICaptureDetails</param>
|
||||||
public static void SendImage(Image image, ICaptureDetails captureDetails) {
|
public static void SendImage(Image image, ICaptureDetails captureDetails) {
|
||||||
string tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
|
string tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, new OutputSettings());
|
||||||
|
|
||||||
if (tmpFile != null) {
|
if (tmpFile != null) {
|
||||||
// Store the list of currently active windows, so we can make sure we show the email window later!
|
// Store the list of currently active windows, so we can make sure we show the email window later!
|
||||||
|
|
|
@ -95,16 +95,16 @@ namespace Greenshot.Helpers {
|
||||||
#region Implementation of IGreenshotPluginHost
|
#region Implementation of IGreenshotPluginHost
|
||||||
private ContextMenuStrip mainMenu = null;
|
private ContextMenuStrip mainMenu = null;
|
||||||
|
|
||||||
public void SaveToStream(Image img, Stream stream, OutputFormat extension, int quality, bool reduceColors) {
|
public void SaveToStream(Image img, Stream stream, OutputSettings outputSettings) {
|
||||||
ImageOutput.SaveToStream(img, stream, extension, quality, reduceColors);
|
ImageOutput.SaveToStream(img, stream, outputSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string SaveToTmpFile(Image img, OutputFormat outputFormat, int quality, bool reduceColors) {
|
public string SaveToTmpFile(Image img, OutputSettings outputSettings) {
|
||||||
return ImageOutput.SaveToTmpFile(img, outputFormat, quality, reduceColors);
|
return ImageOutput.SaveToTmpFile(img, outputSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputFormat outputFormat, int quality, bool reduceColors) {
|
public string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputSettings outputSettings) {
|
||||||
return ImageOutput.SaveNamedTmpFile(image, captureDetails, outputFormat, quality, reduceColors);
|
return ImageOutput.SaveNamedTmpFile(image, captureDetails, outputSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetFilename(OutputFormat format, ICaptureDetails captureDetails) {
|
public string GetFilename(OutputFormat format, ICaptureDetails captureDetails) {
|
||||||
|
|
|
@ -188,25 +188,25 @@ Details about the GNU General Public License:
|
||||||
Greenshot Help
|
Greenshot Help
|
||||||
</resource>
|
</resource>
|
||||||
<resource name="settings_jpegsettings">
|
<resource name="settings_jpegsettings">
|
||||||
JPEG settings
|
Quality settings
|
||||||
</resource>
|
</resource>
|
||||||
<resource name="settings_jpegquality">
|
<resource name="settings_jpegquality">
|
||||||
JPEG quality
|
JPEG quality
|
||||||
</resource>
|
</resource>
|
||||||
<resource name="settings_alwaysshowjpegqualitydialog">
|
<resource name="settings_alwaysshowjpegqualitydialog">
|
||||||
Show JPEG quality dialog every time a JPEG image is saved
|
Show quality dialog every time an image is saved
|
||||||
</resource>
|
</resource>
|
||||||
<resource name="jpegqualitydialog_title">
|
<resource name="jpegqualitydialog_title">
|
||||||
Greenshot quality
|
Greenshot quality
|
||||||
</resource>
|
</resource>
|
||||||
<resource name="jpegqualitydialog_choosejpegquality">
|
<resource name="jpegqualitydialog_choosejpegquality">
|
||||||
Please choose the quality for your JPEG image.
|
Please choose the quality for your image.
|
||||||
</resource>
|
</resource>
|
||||||
<resource name="jpegqualitydialog_dontaskagain">
|
<resource name="jpegqualitydialog_dontaskagain">
|
||||||
Save as default quality and do not ask again
|
Save as default quality and do not ask again
|
||||||
</resource>
|
</resource>
|
||||||
<resource name="reduce_colors">
|
<resource name="settings_reducecolors">
|
||||||
Reduce the amount of colors to 256 (can have impact on quality!)
|
Reduce the amount of colors to a maximum of 256
|
||||||
</resource>
|
</resource>
|
||||||
<resource name="editor_forecolor">
|
<resource name="editor_forecolor">
|
||||||
Line color
|
Line color
|
||||||
|
|
|
@ -142,9 +142,10 @@ namespace GreenshotConfluencePlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool upload(Image image, Page page, string filename, bool openPage) {
|
private bool upload(Image image, Page page, string filename, bool openPage) {
|
||||||
|
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
using (MemoryStream stream = new MemoryStream()) {
|
using (MemoryStream stream = new MemoryStream()) {
|
||||||
ConfluencePlugin.Host.SaveToStream(image, stream, config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
ConfluencePlugin.Host.SaveToStream(image, stream, outputSettings);
|
||||||
// COPY buffer to array
|
// COPY buffer to array
|
||||||
buffer = stream.ToArray();
|
buffer = stream.ToArray();
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,10 +73,12 @@ namespace ExternalCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
|
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
|
||||||
|
OutputSettings outputSettings = new OutputSettings();
|
||||||
|
|
||||||
string fullPath = captureDetails.Filename;
|
string fullPath = captureDetails.Filename;
|
||||||
if (fullPath == null) {
|
if (fullPath == null) {
|
||||||
using (Image image = surface.GetImageForExport()) {
|
using (Image image = surface.GetImageForExport()) {
|
||||||
fullPath = host.SaveNamedTmpFile(image, captureDetails, OutputFormat.png, 100, false);
|
fullPath = host.SaveNamedTmpFile(image, captureDetails, outputSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (presetCommand != null) {
|
if (presetCommand != null) {
|
||||||
|
|
|
@ -130,10 +130,11 @@ namespace GreenshotImgurPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Upload(ICaptureDetails captureDetails, Image image, out string uploadURL) {
|
public bool Upload(ICaptureDetails captureDetails, Image image, out string uploadURL) {
|
||||||
|
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
||||||
using (MemoryStream stream = new MemoryStream()) {
|
using (MemoryStream stream = new MemoryStream()) {
|
||||||
BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(Attributes.Name, Language.GetString("imgur", LangKey.communication_wait));
|
BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(Attributes.Name, Language.GetString("imgur", LangKey.communication_wait));
|
||||||
|
|
||||||
host.SaveToStream(image, stream, config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
host.SaveToStream(image, stream, outputSettings);
|
||||||
try {
|
try {
|
||||||
string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails));
|
string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails));
|
||||||
ImgurInfo imgurInfo = ImgurUtils.UploadToImgur(stream.GetBuffer(), (int)stream.Length, captureDetails.DateTime.ToString(), filename);
|
ImgurInfo imgurInfo = ImgurUtils.UploadToImgur(stream.GetBuffer(), (int)stream.Length, captureDetails.DateTime.ToString(), filename);
|
||||||
|
@ -170,10 +171,11 @@ namespace GreenshotImgurPlugin {
|
||||||
public void EditMenuClick(object sender, EventArgs eventArgs) {
|
public void EditMenuClick(object sender, EventArgs eventArgs) {
|
||||||
ToolStripMenuItem item = (ToolStripMenuItem)sender;
|
ToolStripMenuItem item = (ToolStripMenuItem)sender;
|
||||||
IImageEditor imageEditor = (IImageEditor)item.Tag;
|
IImageEditor imageEditor = (IImageEditor)item.Tag;
|
||||||
|
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
||||||
using (MemoryStream stream = new MemoryStream()) {
|
using (MemoryStream stream = new MemoryStream()) {
|
||||||
BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(Attributes.Name, Language.GetString("imgur", LangKey.communication_wait));
|
BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(Attributes.Name, Language.GetString("imgur", LangKey.communication_wait));
|
||||||
|
|
||||||
imageEditor.SaveToStream(stream, config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
imageEditor.SaveToStream(stream, outputSettings);
|
||||||
try {
|
try {
|
||||||
string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, imageEditor.CaptureDetails));
|
string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, imageEditor.CaptureDetails));
|
||||||
ImgurInfo imgurInfo = ImgurUtils.UploadToImgur(stream.GetBuffer(), (int)stream.Length, imageEditor.CaptureDetails.Title, filename);
|
ImgurInfo imgurInfo = ImgurUtils.UploadToImgur(stream.GetBuffer(), (int)stream.Length, imageEditor.CaptureDetails.Title, filename);
|
||||||
|
|
|
@ -104,10 +104,11 @@ namespace GreenshotJiraPlugin {
|
||||||
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
|
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
|
||||||
string filename = Path.GetFileName(jiraPlugin.Host.GetFilename(config.UploadFormat, captureDetails));
|
string filename = Path.GetFileName(jiraPlugin.Host.GetFilename(config.UploadFormat, captureDetails));
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
|
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
||||||
if (jira != null) {
|
if (jira != null) {
|
||||||
using (MemoryStream stream = new MemoryStream()) {
|
using (MemoryStream stream = new MemoryStream()) {
|
||||||
using (Image image = surface.GetImageForExport()) {
|
using (Image image = surface.GetImageForExport()) {
|
||||||
jiraPlugin.Host.SaveToStream(image, stream, config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
jiraPlugin.Host.SaveToStream(image, stream, outputSettings);
|
||||||
}
|
}
|
||||||
// COPY stream to buffer
|
// COPY stream to buffer
|
||||||
buffer = stream.ToArray();
|
buffer = stream.ToArray();
|
||||||
|
@ -134,7 +135,7 @@ namespace GreenshotJiraPlugin {
|
||||||
if (result == DialogResult.OK) {
|
if (result == DialogResult.OK) {
|
||||||
using (MemoryStream stream = new MemoryStream()) {
|
using (MemoryStream stream = new MemoryStream()) {
|
||||||
using (Image image = surface.GetImageForExport()) {
|
using (Image image = surface.GetImageForExport()) {
|
||||||
jiraPlugin.Host.SaveToStream(image, stream, config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
jiraPlugin.Host.SaveToStream(image, stream, outputSettings);
|
||||||
}
|
}
|
||||||
// COPY stream to buffer
|
// COPY stream to buffer
|
||||||
buffer = stream.ToArray();
|
buffer = stream.ToArray();
|
||||||
|
|
|
@ -49,10 +49,8 @@ namespace Greenshot.Plugin {
|
||||||
/// Will save the current Image in the supplied format to the given stream
|
/// Will save the current Image in the supplied format to the given stream
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="stream">The stream the image is stored on</param>
|
/// <param name="stream">The stream the image is stored on</param>
|
||||||
/// <param name="extension">The image type (extension), e.g. "png", "jpg", "bmp"</param>
|
/// <param name="outputSettings">OutputSettings</param>
|
||||||
/// <param name="quality">Only needed for "jpg"</param>
|
void SaveToStream(Stream stream, OutputSettings outputSettings);
|
||||||
/// <param name="reduceColors">reduce the amount of colors to 256</param>
|
|
||||||
void SaveToStream(Stream stream, OutputFormat extension, int quality, bool reduceColors);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the ToolStripMenuItem where plugins can place their Menu entrys
|
/// Get the ToolStripMenuItem where plugins can place their Menu entrys
|
||||||
|
|
|
@ -25,6 +25,7 @@ using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using GreenshotPlugin.Core;
|
using GreenshotPlugin.Core;
|
||||||
|
using Greenshot.IniFile;
|
||||||
|
|
||||||
namespace Greenshot.Plugin {
|
namespace Greenshot.Plugin {
|
||||||
[Serializable]
|
[Serializable]
|
||||||
|
@ -73,6 +74,52 @@ namespace Greenshot.Plugin {
|
||||||
// Delegates for hooking up events.
|
// Delegates for hooking up events.
|
||||||
public delegate void HotKeyHandler();
|
public delegate void HotKeyHandler();
|
||||||
|
|
||||||
|
public class OutputSettings {
|
||||||
|
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
private bool reduceColors;
|
||||||
|
|
||||||
|
public OutputSettings() {
|
||||||
|
Format = conf.OutputFileFormat;
|
||||||
|
JPGQuality = conf.OutputFileJpegQuality;
|
||||||
|
ReduceColors = conf.OutputFileReduceColors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutputSettings(OutputFormat format) : this() {
|
||||||
|
Format = format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutputSettings(OutputFormat format, int quality) : this(format) {
|
||||||
|
JPGQuality = quality;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutputSettings(OutputFormat format, int quality, bool reduceColors) : this(format, quality) {
|
||||||
|
ReduceColors = reduceColors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutputFormat Format {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int JPGQuality {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ReduceColors {
|
||||||
|
get {
|
||||||
|
// Fix for Bug #3468436, force quantizing when output format is gif as this has only 256 colors!
|
||||||
|
if (OutputFormat.gif.Equals(Format)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return reduceColors;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
reduceColors = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This interface is the GreenshotPluginHost, that which "Hosts" the plugin.
|
/// This interface is the GreenshotPluginHost, that which "Hosts" the plugin.
|
||||||
/// For Greenshot this is implmented in the PluginHelper
|
/// For Greenshot this is implmented in the PluginHelper
|
||||||
|
@ -87,29 +134,23 @@ namespace Greenshot.Plugin {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="image">The Image to save</param>
|
/// <param name="image">The Image to save</param>
|
||||||
/// <param name="stream">The Stream to save to</param>
|
/// <param name="stream">The Stream to save to</param>
|
||||||
/// <param name="format">The format to save with (png, jpg etc)</param>
|
/// <param name="outputSettings">OutputSettings</param>
|
||||||
/// <param name="quality">Jpeg quality</param>
|
void SaveToStream(Image image, Stream stream, OutputSettings outputSettings);
|
||||||
/// <param name="reduceColors">reduce the amount of colors to 256</param>
|
|
||||||
void SaveToStream(Image image, Stream stream, OutputFormat format, int quality, bool reduceColors);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves the image to a temp file (random name) using the specified outputformat
|
/// Saves the image to a temp file (random name) using the specified outputformat
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="image">The Image to save</param>
|
/// <param name="image">The Image to save</param>
|
||||||
/// <param name="format">The format to save with (png, jpg etc)</param>
|
/// <param name="outputSettings">OutputSettings</param>
|
||||||
/// <param name="quality">Jpeg quality</param>
|
string SaveToTmpFile(Image image, OutputSettings outputSettings);
|
||||||
/// <param name="reduceColors">reduce the amount of colors to 256</param>
|
|
||||||
string SaveToTmpFile(Image image, OutputFormat outputFormat, int quality, bool reduceColors);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves the image to a temp file, but the name is build with the capture details & pattern
|
/// Saves the image to a temp file, but the name is build with the capture details & pattern
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="image">The Image to save</param>
|
/// <param name="image">The Image to save</param>
|
||||||
/// <param name="captureDetails">captureDetails with the information to build the filename</param>
|
/// <param name="captureDetails">captureDetails with the information to build the filename</param>
|
||||||
/// <param name="outputformat">The format to save with (png, jpg etc)</param>
|
/// <param name="outputSettings">OutputSettings</param>
|
||||||
/// <param name="quality">Jpeg quality</param>
|
string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputSettings outputSettings);
|
||||||
/// <param name="reduceColors">reduce the amount of colors to 256</param>
|
|
||||||
string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputFormat outputFormat, int quality, bool reduceColors);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return a filename for the current image format (png,jpg etc) with the default file pattern
|
/// Return a filename for the current image format (png,jpg etc) with the default file pattern
|
||||||
|
|
|
@ -63,11 +63,13 @@ namespace PluginExample {
|
||||||
|
|
||||||
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
|
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
|
||||||
CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
|
CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
OutputSettings outputSettings = new OutputSettings();
|
||||||
|
|
||||||
string file = host.GetFilename(OutputFormat.png, null);
|
string file = host.GetFilename(OutputFormat.png, null);
|
||||||
string filePath = Path.Combine(config.OutputFilePath, file);
|
string filePath = Path.Combine(config.OutputFilePath, file);
|
||||||
using (FileStream stream = new FileStream(filePath, FileMode.Create)) {
|
using (FileStream stream = new FileStream(filePath, FileMode.Create)) {
|
||||||
using (Image image = surface.GetImageForExport()) {
|
using (Image image = surface.GetImageForExport()) {
|
||||||
host.SaveToStream(image, stream, OutputFormat.png, config.OutputFileJpegQuality, config.OutputFileReduceColors);
|
host.SaveToStream(image, stream, outputSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MessageBox.Show("Saved test file to: " + filePath);
|
MessageBox.Show("Saved test file to: " + filePath);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue