diff --git a/Greenshot/Destinations/ClipboardDestination.cs b/Greenshot/Destinations/ClipboardDestination.cs
index 79bcfe698..fe9cb0509 100644
--- a/Greenshot/Destinations/ClipboardDestination.cs
+++ b/Greenshot/Destinations/ClipboardDestination.cs
@@ -71,10 +71,8 @@ namespace Greenshot.Destinations {
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
try {
- using (Image image = surface.GetImageForExport()) {
- ClipboardHelper.SetClipboardData(image);
- exportInformation.ExportMade = true;
- }
+ ClipboardHelper.SetClipboardData(surface);
+ exportInformation.ExportMade = true;
} catch (Exception) {
// TODO: Change to general logic in ProcessExport
surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetString(LangKey.editor_clipboardfailed));
diff --git a/GreenshotBoxPlugin/BoxDestination.cs b/GreenshotBoxPlugin/BoxDestination.cs
index 36d817548..b0f9b6028 100644
--- a/GreenshotBoxPlugin/BoxDestination.cs
+++ b/GreenshotBoxPlugin/BoxDestination.cs
@@ -55,12 +55,10 @@ namespace GreenshotBoxPlugin {
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
- using (Image image = surface.GetImageForExport()) {
- string uploadUrl = plugin.Upload(captureDetails, image);
- if (uploadUrl != null) {
- exportInformation.ExportMade = true;
- exportInformation.Uri = uploadUrl;
- }
+ string uploadUrl = plugin.Upload(captureDetails, surface);
+ if (uploadUrl != null) {
+ exportInformation.ExportMade = true;
+ exportInformation.Uri = uploadUrl;
}
ProcessExport(exportInformation, surface);
return exportInformation;
diff --git a/GreenshotBoxPlugin/BoxPlugin.cs b/GreenshotBoxPlugin/BoxPlugin.cs
index 5945c5259..813a1bf29 100644
--- a/GreenshotBoxPlugin/BoxPlugin.cs
+++ b/GreenshotBoxPlugin/BoxPlugin.cs
@@ -110,12 +110,12 @@ namespace GreenshotBoxPlugin {
///
/// This will be called when the menu item in the Editor is clicked
///
- public string Upload(ICaptureDetails captureDetails, Image image) {
+ public string Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload) {
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, false);
try {
string url = null;
string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
- ImageContainer imageToUpload = new ImageContainer(image, outputSettings, filename);
+ SurfaceContainer imageToUpload = new SurfaceContainer(surfaceToUpload, outputSettings, filename);
new PleaseWaitForm().ShowAndWait(BoxPlugin.Attributes.Name, Language.GetString("box", LangKey.communication_wait),
delegate() {
diff --git a/GreenshotBoxPlugin/BoxUtils.cs b/GreenshotBoxPlugin/BoxUtils.cs
index 3c6352ad1..4a5665ce7 100644
--- a/GreenshotBoxPlugin/BoxUtils.cs
+++ b/GreenshotBoxPlugin/BoxUtils.cs
@@ -92,7 +92,7 @@ namespace GreenshotBoxPlugin {
///
/// byte[] with image data
/// url to uploaded image
- public static string UploadToBox(ImageContainer image, string title, string filename) {
+ public static string UploadToBox(SurfaceContainer image, string title, string filename) {
string folderId = "0";
if (string.IsNullOrEmpty(config.BoxToken)) {
if (!Authorize()) {
diff --git a/GreenshotConfluencePlugin/ConfluenceDestination.cs b/GreenshotConfluencePlugin/ConfluenceDestination.cs
index 5f283f9fe..55e69c68f 100644
--- a/GreenshotConfluencePlugin/ConfluenceDestination.cs
+++ b/GreenshotConfluencePlugin/ConfluenceDestination.cs
@@ -136,33 +136,31 @@ namespace GreenshotConfluencePlugin {
}
}
if (selectedPage != null) {
- using (Image image = surface.GetImageForExport()) {
- string errorMessage;
- bool uploaded = upload(image, selectedPage, filename, out errorMessage);
- if (uploaded) {
- if (openPage) {
- try {
- Process.Start(selectedPage.Url);
- } catch { }
- }
- exportInformation.ExportMade = true;
- exportInformation.Uri = selectedPage.Url;
- } else {
- exportInformation.ErrorMessage = errorMessage;
+ string errorMessage;
+ bool uploaded = upload(surface, selectedPage, filename, out errorMessage);
+ if (uploaded) {
+ if (openPage) {
+ try {
+ Process.Start(selectedPage.Url);
+ } catch { }
}
+ exportInformation.ExportMade = true;
+ exportInformation.Uri = selectedPage.Url;
+ } else {
+ exportInformation.ErrorMessage = errorMessage;
}
}
ProcessExport(exportInformation, surface);
return exportInformation;
}
-
- private bool upload(Image image, Page page, string filename, out string errorMessage) {
+
+ private bool upload(ISurface surfaceToUpload, Page page, string filename, out string errorMessage) {
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
errorMessage = null;
try {
new PleaseWaitForm().ShowAndWait(Description, Language.GetString("confluence", LangKey.communication_wait),
delegate() {
- ConfluencePlugin.ConfluenceConnector.addAttachment(page.id, "image/" + config.UploadFormat.ToString().ToLower(), null, filename, new ImageContainer(image, outputSettings, filename));
+ ConfluencePlugin.ConfluenceConnector.addAttachment(page.id, "image/" + config.UploadFormat.ToString().ToLower(), null, filename, new SurfaceContainer(surfaceToUpload, outputSettings, filename));
}
);
LOG.Debug("Uploaded to Confluence.");
diff --git a/GreenshotDropboxPlugin/DropboxDestination.cs b/GreenshotDropboxPlugin/DropboxDestination.cs
index 8dea2a10a..e1f84cb0b 100644
--- a/GreenshotDropboxPlugin/DropboxDestination.cs
+++ b/GreenshotDropboxPlugin/DropboxDestination.cs
@@ -54,15 +54,13 @@ namespace GreenshotDropboxPlugin {
public override ExportInformation ExportCapture(bool manually, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
- using (Image image = surface.GetImageForExport()) {
- string uploadURL = null;
- bool uploaded = plugin.Upload(captureDetails, image, out uploadURL);
- if (uploaded) {
- exportInformation.Uri = uploadURL;
- exportInformation.ExportMade = true;
- if (config.AfterUploadLinkToClipBoard) {
- ClipboardHelper.SetClipboardData(uploadURL);
- }
+ string uploadURL = null;
+ bool uploaded = plugin.Upload(captureDetails, surface, out uploadURL);
+ if (uploaded) {
+ exportInformation.Uri = uploadURL;
+ exportInformation.ExportMade = true;
+ if (config.AfterUploadLinkToClipBoard) {
+ ClipboardHelper.SetClipboardData(uploadURL);
}
}
ProcessExport(exportInformation, surface);
diff --git a/GreenshotDropboxPlugin/DropboxPlugin.cs b/GreenshotDropboxPlugin/DropboxPlugin.cs
index 766f9c626..b00f0c53f 100644
--- a/GreenshotDropboxPlugin/DropboxPlugin.cs
+++ b/GreenshotDropboxPlugin/DropboxPlugin.cs
@@ -111,7 +111,7 @@ namespace GreenshotDropboxPlugin {
///
/// This will be called when the menu item in the Editor is clicked
///
- public bool Upload(ICaptureDetails captureDetails, Image image, out string uploadUrl) {
+ public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadUrl) {
uploadUrl = null;
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, false);
try {
@@ -119,7 +119,7 @@ namespace GreenshotDropboxPlugin {
new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("dropbox", LangKey.communication_wait),
delegate() {
string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
- dropboxUrl = DropboxUtils.UploadToDropbox(image, outputSettings, filename);
+ dropboxUrl = DropboxUtils.UploadToDropbox(surfaceToUpload, outputSettings, filename);
}
);
if (dropboxUrl == null) {
diff --git a/GreenshotDropboxPlugin/DropboxUtils.cs b/GreenshotDropboxPlugin/DropboxUtils.cs
index e098ab3e3..fef8bd556 100644
--- a/GreenshotDropboxPlugin/DropboxUtils.cs
+++ b/GreenshotDropboxPlugin/DropboxUtils.cs
@@ -36,7 +36,7 @@ namespace GreenshotDropboxPlugin {
private DropboxUtils() {
}
- public static string UploadToDropbox(Image image, OutputSettings outputSettings, string filename) {
+ public static string UploadToDropbox(ISurface surfaceToUpload, OutputSettings outputSettings, string filename) {
OAuthSession oAuth = new OAuthSession(DropBoxCredentials.CONSUMER_KEY, DropBoxCredentials.CONSUMER_SECRET);
oAuth.BrowserSize = new Size(1080, 650);
oAuth.CheckVerifier = false;
@@ -48,7 +48,7 @@ namespace GreenshotDropboxPlugin {
oAuth.TokenSecret = config.DropboxTokenSecret;
try {
- ImageContainer imageToUpload = new ImageContainer(image, outputSettings, filename);
+ SurfaceContainer imageToUpload = new SurfaceContainer(surfaceToUpload, outputSettings, filename);
string uploadResponse = oAuth.MakeOAuthRequest(HTTPMethod.POST, "https://api-content.dropbox.com/1/files_put/sandbox/" + OAuthSession.UrlEncode3986(filename), null, null, imageToUpload);
LOG.DebugFormat("Upload response: {0}", uploadResponse);
} catch (Exception ex) {
diff --git a/GreenshotFlickrPlugin/FlickrDestination.cs b/GreenshotFlickrPlugin/FlickrDestination.cs
index 609c962cb..180726ba2 100644
--- a/GreenshotFlickrPlugin/FlickrDestination.cs
+++ b/GreenshotFlickrPlugin/FlickrDestination.cs
@@ -54,9 +54,7 @@ namespace GreenshotFlickrPlugin {
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
- using (Image image = surface.GetImageForExport()) {
- plugin.Upload(captureDetails, image, exportInformation);
- }
+ plugin.Upload(captureDetails, surface, exportInformation);
ProcessExport(exportInformation, surface);
return exportInformation;
}
diff --git a/GreenshotFlickrPlugin/FlickrPlugin.cs b/GreenshotFlickrPlugin/FlickrPlugin.cs
index c0ebc4da3..f2909cbf6 100644
--- a/GreenshotFlickrPlugin/FlickrPlugin.cs
+++ b/GreenshotFlickrPlugin/FlickrPlugin.cs
@@ -110,14 +110,14 @@ namespace GreenshotFlickrPlugin
config.ShowConfigDialog();
}
- public void Upload(ICaptureDetails captureDetails, Image image, ExportInformation exportInformation) {
+ public void Upload(ICaptureDetails captureDetails, ISurface surface, ExportInformation exportInformation) {
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, false);
try {
string flickrUrl = null;
new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("flickr", LangKey.communication_wait),
delegate() {
string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
- flickrUrl = FlickrUtils.UploadToFlickr(image, outputSettings, captureDetails.Title, filename);
+ flickrUrl = FlickrUtils.UploadToFlickr(surface, outputSettings, captureDetails.Title, filename);
}
);
diff --git a/GreenshotFlickrPlugin/FlickrUtils.cs b/GreenshotFlickrPlugin/FlickrUtils.cs
index 0119e7bde..2f6effafb 100644
--- a/GreenshotFlickrPlugin/FlickrUtils.cs
+++ b/GreenshotFlickrPlugin/FlickrUtils.cs
@@ -44,7 +44,7 @@ namespace GreenshotFlickrPlugin {
///
/// byte[] with image data
/// url to image
- public static string UploadToFlickr(Image image, OutputSettings outputSettings, string title, string filename) {
+ public static string UploadToFlickr(ISurface surfaceToUpload, OutputSettings outputSettings, string title, string filename) {
OAuthSession oAuth = new OAuthSession(FlickrCredentials.ConsumerKey, FlickrCredentials.ConsumerSecret);
oAuth.BrowserSize = new Size(520, 800);
oAuth.CheckVerifier = false;
@@ -76,7 +76,7 @@ namespace GreenshotFlickrPlugin {
signedParameters.Add("safety_level", string.Format("{0}", (int)config.SafetyLevel));
signedParameters.Add("hidden", config.HiddenFromSearch?"1":"2");
IDictionary otherParameters = new Dictionary();
- otherParameters.Add("photo", new ImageContainer(image, outputSettings, filename));
+ otherParameters.Add("photo", new SurfaceContainer(surfaceToUpload, outputSettings, filename));
string response = oAuth.MakeOAuthRequest(HTTPMethod.POST, "http://api.flickr.com/services/upload/", signedParameters, otherParameters, null);
string photoId = GetPhotoId(response);
diff --git a/GreenshotImgurPlugin/ImgurDestination.cs b/GreenshotImgurPlugin/ImgurDestination.cs
index 6fc7ea707..e451caff8 100644
--- a/GreenshotImgurPlugin/ImgurDestination.cs
+++ b/GreenshotImgurPlugin/ImgurDestination.cs
@@ -58,11 +58,9 @@ namespace GreenshotImgurPlugin {
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
- using (Image image = surface.GetImageForExport()) {
- string uploadURL = null;
- exportInformation.ExportMade = plugin.Upload(captureDetails, image, out uploadURL);
- exportInformation.Uri = uploadURL;
- }
+ string uploadURL = null;
+ exportInformation.ExportMade = plugin.Upload(captureDetails, surface, out uploadURL);
+ exportInformation.Uri = uploadURL;
ProcessExport(exportInformation, surface);
return exportInformation;
}
diff --git a/GreenshotImgurPlugin/ImgurPlugin.cs b/GreenshotImgurPlugin/ImgurPlugin.cs
index be2fe9d11..e252dfc84 100644
--- a/GreenshotImgurPlugin/ImgurPlugin.cs
+++ b/GreenshotImgurPlugin/ImgurPlugin.cs
@@ -151,7 +151,7 @@ namespace GreenshotImgurPlugin {
///
/// out string for the url
/// true if the upload succeeded
- public bool Upload(ICaptureDetails captureDetails, Image image, out string uploadURL) {
+ public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadURL) {
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
try {
string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
@@ -160,7 +160,7 @@ namespace GreenshotImgurPlugin {
// Run upload in the background
new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("imgur", LangKey.communication_wait),
delegate() {
- imgurInfo = ImgurUtils.UploadToImgur(image, outputSettings, captureDetails.Title, filename);
+ imgurInfo = ImgurUtils.UploadToImgur(surfaceToUpload, outputSettings, captureDetails.Title, filename);
LOG.InfoFormat("Storing imgur upload for hash {0} and delete hash {1}", imgurInfo.Hash, imgurInfo.DeleteHash);
config.ImgurUploadHistory.Add(imgurInfo.Hash, imgurInfo.DeleteHash);
config.runtimeImgurHistory.Add(imgurInfo.Hash, imgurInfo);
@@ -168,7 +168,10 @@ namespace GreenshotImgurPlugin {
}
);
- imgurInfo.Image = ImageHelper.CreateThumbnail(image, 90, 90);
+ // TODO: Optimize a second call for export
+ using (Image tmpImage = surfaceToUpload.GetImageForExport()) {
+ imgurInfo.Image = ImageHelper.CreateThumbnail(tmpImage, 90, 90);
+ }
IniConfig.Save();
uploadURL = null;
try {
diff --git a/GreenshotImgurPlugin/ImgurUtils.cs b/GreenshotImgurPlugin/ImgurUtils.cs
index 06b6eedf9..6505145a1 100644
--- a/GreenshotImgurPlugin/ImgurUtils.cs
+++ b/GreenshotImgurPlugin/ImgurUtils.cs
@@ -94,12 +94,12 @@ namespace GreenshotImgurPlugin {
/// Do the actual upload to Imgur
/// For more details on the available parameters, see: http://api.imgur.com/resources_anon
///
- /// Image to upload
+ /// ISurface to upload
/// OutputSettings for the image file format
/// Title
/// Filename
/// ImgurInfo with details
- public static ImgurInfo UploadToImgur(Image image, OutputSettings outputSettings, string title, string filename) {
+ public static ImgurInfo UploadToImgur(ISurface surfaceToUpload, OutputSettings outputSettings, string title, string filename) {
IDictionary uploadParameters = new Dictionary();
IDictionary otherParameters = new Dictionary();
// add title
@@ -120,7 +120,7 @@ namespace GreenshotImgurPlugin {
webRequest.ServicePoint.Expect100Continue = false;
try {
using (var requestStream = webRequest.GetRequestStream()) {
- ImageOutput.SaveToStream(image, requestStream, outputSettings);
+ ImageOutput.SaveToStream(surfaceToUpload, requestStream, outputSettings);
}
using (WebResponse response = webRequest.GetResponse()) {
@@ -156,7 +156,7 @@ namespace GreenshotImgurPlugin {
IniConfig.Save();
}
try {
- otherParameters.Add("image", new ImageContainer(image, outputSettings, filename));
+ otherParameters.Add("image", new SurfaceContainer(surfaceToUpload, outputSettings, filename));
responseString = oAuth.MakeOAuthRequest(HTTPMethod.POST, "http://api.imgur.com/2/account/images.xml", uploadParameters, otherParameters, null);
} catch (Exception ex) {
LOG.Error("Upload to imgur gave an exeption: ", ex);
diff --git a/GreenshotJiraPlugin/JiraDestination.cs b/GreenshotJiraPlugin/JiraDestination.cs
index 28fc46307..6804a4ea0 100644
--- a/GreenshotJiraPlugin/JiraDestination.cs
+++ b/GreenshotJiraPlugin/JiraDestination.cs
@@ -99,25 +99,24 @@ namespace GreenshotJiraPlugin {
}
}
- public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
+ public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surfaceToUpload, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
if (jira != null) {
- using (Image image = surface.GetImageForExport()) {
- try {
- // Run upload in the background
- new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
- delegate() {
- jiraPlugin.JiraConnector.addAttachment(jira.Key, filename, new ImageContainer(image, outputSettings, filename));
- }
- );
- LOG.Debug("Uploaded to Jira.");
- exportInformation.ExportMade = true;
- exportInformation.Uri = surface.UploadURL;
- } catch (Exception e) {
- MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
- }
+ try {
+ // Run upload in the background
+ new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
+ delegate() {
+ jiraPlugin.JiraConnector.addAttachment(jira.Key, filename, new SurfaceContainer(surfaceToUpload, outputSettings, filename));
+ }
+ );
+ LOG.Debug("Uploaded to Jira.");
+ exportInformation.ExportMade = true;
+ // TODO: This can't work:
+ exportInformation.Uri = surfaceToUpload.UploadURL;
+ } catch (Exception e) {
+ MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
}
} else {
JiraForm jiraForm = new JiraForm(jiraPlugin.JiraConnector);
@@ -126,24 +125,23 @@ namespace GreenshotJiraPlugin {
DialogResult result = jiraForm.ShowDialog();
if (result == DialogResult.OK) {
try {
- using (Image image = surface.GetImageForExport()) {
- // Run upload in the background
- new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
- delegate() {
- jiraForm.upload(new ImageContainer(image, outputSettings, filename));
- }
- );
- }
+ // Run upload in the background
+ new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
+ delegate() {
+ jiraForm.upload(new SurfaceContainer(surfaceToUpload, outputSettings, filename));
+ }
+ );
LOG.Debug("Uploaded to Jira.");
exportInformation.ExportMade = true;
- exportInformation.Uri = surface.UploadURL;
+ // TODO: This can't work:
+ exportInformation.Uri = surfaceToUpload.UploadURL;
} catch(Exception e) {
MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
}
}
}
}
- ProcessExport(exportInformation, surface);
+ ProcessExport(exportInformation, surfaceToUpload);
return exportInformation;
}
}
diff --git a/GreenshotOCRPlugin/OCRPlugin.cs b/GreenshotOCRPlugin/OCRPlugin.cs
index d1d21e9f9..0034610e5 100644
--- a/GreenshotOCRPlugin/OCRPlugin.cs
+++ b/GreenshotOCRPlugin/OCRPlugin.cs
@@ -138,24 +138,10 @@ namespace GreenshotOCR {
public string DoOCR(ISurface surface) {
string filePath = null;
OutputSettings outputSettings = new OutputSettings(OutputFormat.bmp, 0, true);
+ // TODO: Add some filter & output settings so the output image is easier to process for the MODI-OCR code
+ // Also we need to check the size, resize if needed to 130x130 this is the minimum
+ filePath = ImageOutput.SaveToTmpFile(surface, outputSettings, null);
- // Use surface background image, this prevents having a mouse cursor in the way.
- Image capturedImage = surface.Image;
- if (capturedImage.Width < MIN_WIDTH || capturedImage.Height < MIN_HEIGHT) {
- LOG.Debug("Captured image is not big enough for OCR, growing image...");
- int newWidth = Math.Max(capturedImage.Width, MIN_WIDTH);
- int newHeight = Math.Max(capturedImage.Height, MIN_HEIGHT);
- using (Image tmpImage = new Bitmap(newWidth, newHeight, capturedImage.PixelFormat)) {
- using (Graphics graphics = Graphics.FromImage(tmpImage)) {
- graphics.Clear(Color.White);
- graphics.DrawImage(capturedImage, Point.Empty);
- }
- filePath = ImageOutput.SaveToTmpFile(tmpImage, outputSettings, null);
- }
- } else {
- filePath = ImageOutput.SaveToTmpFile(capturedImage, outputSettings, null);
- }
-
LOG.Debug("Saved tmp file to: " + filePath);
string text = "";
diff --git a/GreenshotOfficePlugin/Destinations/OneNoteDestination.cs b/GreenshotOfficePlugin/Destinations/OneNoteDestination.cs
index 2a3fe4dff..bef298faa 100644
--- a/GreenshotOfficePlugin/Destinations/OneNoteDestination.cs
+++ b/GreenshotOfficePlugin/Destinations/OneNoteDestination.cs
@@ -109,15 +109,13 @@ namespace GreenshotOfficePlugin {
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
- using (Image image = surface.GetImageForExport()) {
- if (page != null) {
- try {
- OneNoteExporter.ExportToPage((Bitmap)image, page);
- exportInformation.ExportMade = true;
- } catch (Exception ex) {
- exportInformation.ErrorMessage = ex.Message;
- LOG.Error(ex);
- }
+ if (page != null) {
+ try {
+ OneNoteExporter.ExportToPage(surface, page);
+ exportInformation.ExportMade = true;
+ } catch (Exception ex) {
+ exportInformation.ErrorMessage = ex.Message;
+ LOG.Error(ex);
}
}
return exportInformation;
diff --git a/GreenshotOfficePlugin/OfficeExport/OneNoteExporter.cs b/GreenshotOfficePlugin/OfficeExport/OneNoteExporter.cs
index 6a6f14e0e..138930874 100644
--- a/GreenshotOfficePlugin/OfficeExport/OneNoteExporter.cs
+++ b/GreenshotOfficePlugin/OfficeExport/OneNoteExporter.cs
@@ -43,12 +43,12 @@ namespace Greenshot.Interop.Office {
private const string ONENOTE_NAMESPACE_2007 = "http://schemas.microsoft.com/office/onenote/2007/onenote";
private const string ONENOTE_NAMESPACE_2010 = "http://schemas.microsoft.com/office/onenote/2010/onenote";
- public static void ExportToPage(Bitmap imageToExport, OneNotePage page) {
+ public static void ExportToPage(ISurface surfaceToUpload, OneNotePage page) {
using (MemoryStream pngStream = new MemoryStream()) {
OutputSettings pngOutputSettings = new OutputSettings(OutputFormat.png, 100, false);
- ImageOutput.SaveToStream(imageToExport, pngStream, pngOutputSettings);
+ ImageOutput.SaveToStream(surfaceToUpload, pngStream, pngOutputSettings);
string base64String = Convert.ToBase64String(pngStream.GetBuffer());
- string imageXmlStr = string.Format(XML_IMAGE_CONTENT, base64String, imageToExport.Width, imageToExport.Height);
+ string imageXmlStr = string.Format(XML_IMAGE_CONTENT, base64String, surfaceToUpload.Image.Width, surfaceToUpload.Image.Height);
string pageChangesXml = string.Format(XML_OUTLINE, new object[] { imageXmlStr, page.PageID, ONENOTE_NAMESPACE_2010, page.PageName });
using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance()) {
LOG.InfoFormat("Sending XML: {0}", pageChangesXml);
diff --git a/GreenshotPhotobucketPlugin/PhotobucketDestination.cs b/GreenshotPhotobucketPlugin/PhotobucketDestination.cs
index 34595e4a6..db3c031bb 100644
--- a/GreenshotPhotobucketPlugin/PhotobucketDestination.cs
+++ b/GreenshotPhotobucketPlugin/PhotobucketDestination.cs
@@ -58,13 +58,11 @@ namespace GreenshotPhotobucketPlugin {
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
- using (Image image = surface.GetImageForExport()) {
- string uploadURL = null;
- bool uploaded = plugin.Upload(captureDetails, image, out uploadURL);
- if (uploaded) {
- exportInformation.ExportMade = true;
- exportInformation.Uri = uploadURL;
- }
+ string uploadURL = null;
+ bool uploaded = plugin.Upload(captureDetails, surface, out uploadURL);
+ if (uploaded) {
+ exportInformation.ExportMade = true;
+ exportInformation.Uri = uploadURL;
}
ProcessExport(exportInformation, surface);
return exportInformation;
diff --git a/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs b/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs
index 3f947e2ba..a6b857a67 100644
--- a/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs
+++ b/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs
@@ -111,10 +111,10 @@ namespace GreenshotPhotobucketPlugin {
/// Upload the capture to Photobucket
///
///
- ///
+ /// ISurface
/// out string for the url
/// true if the upload succeeded
- public bool Upload(ICaptureDetails captureDetails, Image image, out string uploadURL) {
+ public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadURL) {
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
try {
string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
@@ -123,7 +123,7 @@ namespace GreenshotPhotobucketPlugin {
// Run upload in the background
new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("photobucket", LangKey.communication_wait),
delegate() {
- photobucketInfo = PhotobucketUtils.UploadToPhotobucket(image, outputSettings, captureDetails.Title, filename);
+ photobucketInfo = PhotobucketUtils.UploadToPhotobucket(surfaceToUpload, outputSettings, captureDetails.Title, filename);
}
);
// This causes an exeption if the upload failed :)
diff --git a/GreenshotPhotobucketPlugin/PhotobucketUtils.cs b/GreenshotPhotobucketPlugin/PhotobucketUtils.cs
index bf5d103e6..e09d8295e 100644
--- a/GreenshotPhotobucketPlugin/PhotobucketUtils.cs
+++ b/GreenshotPhotobucketPlugin/PhotobucketUtils.cs
@@ -40,9 +40,8 @@ namespace GreenshotPhotobucketPlugin {
/// Do the actual upload to Photobucket
/// For more details on the available parameters, see: http://api.Photobucket.com/resources_anon
///
- /// byte[] with image data
/// PhotobucketResponse
- public static PhotobucketInfo UploadToPhotobucket(Image image, OutputSettings outputSettings, string title, string filename) {
+ public static PhotobucketInfo UploadToPhotobucket(ISurface surfaceToUpload, OutputSettings outputSettings, string title, string filename) {
string responseString;
OAuthSession oAuth = new OAuthSession(PhotobucketCredentials.ConsumerKey, PhotobucketCredentials.ConsumerSecret);
@@ -94,7 +93,7 @@ namespace GreenshotPhotobucketPlugin {
}
IDictionary unsignedParameters = new Dictionary();
// Add image
- unsignedParameters.Add("uploadfile", new ImageContainer(image, outputSettings, filename));
+ unsignedParameters.Add("uploadfile", new SurfaceContainer(surfaceToUpload, outputSettings, filename));
try {
string apiUrl = "http://api.photobucket.com/album/!/upload";
responseString = oAuth.MakeOAuthRequest(HTTPMethod.POST, apiUrl, apiUrl.Replace("api.photobucket.com", config.SubDomain), signedParameters, unsignedParameters, null);
diff --git a/GreenshotPicasaPlugin/PicasaDestination.cs b/GreenshotPicasaPlugin/PicasaDestination.cs
index 446378ab9..8e489ef09 100644
--- a/GreenshotPicasaPlugin/PicasaDestination.cs
+++ b/GreenshotPicasaPlugin/PicasaDestination.cs
@@ -54,13 +54,11 @@ namespace GreenshotPicasaPlugin {
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
- using (Image image = surface.GetImageForExport()) {
- string uploadURL = null;
- bool uploaded = plugin.Upload(captureDetails, image, out uploadURL);
- if (uploaded) {
- exportInformation.ExportMade = true;
- exportInformation.Uri = uploadURL;
- }
+ string uploadURL = null;
+ bool uploaded = plugin.Upload(captureDetails, surface, out uploadURL);
+ if (uploaded) {
+ exportInformation.ExportMade = true;
+ exportInformation.Uri = uploadURL;
}
ProcessExport(exportInformation, surface);
return exportInformation;
diff --git a/GreenshotPicasaPlugin/PicasaPlugin.cs b/GreenshotPicasaPlugin/PicasaPlugin.cs
index 0af75c7ac..2fe916ae3 100644
--- a/GreenshotPicasaPlugin/PicasaPlugin.cs
+++ b/GreenshotPicasaPlugin/PicasaPlugin.cs
@@ -109,7 +109,7 @@ namespace GreenshotPicasaPlugin {
Configure();
}
- public bool Upload(ICaptureDetails captureDetails, Image image, out string uploadUrl) {
+ public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadUrl) {
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality);
try {
string url = null;
@@ -117,7 +117,7 @@ namespace GreenshotPicasaPlugin {
delegate() {
string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
string contentType = "image/" + config.UploadFormat.ToString();
- url = PicasaUtils.UploadToPicasa(image, outputSettings, captureDetails.Title, filename);
+ url = PicasaUtils.UploadToPicasa(surfaceToUpload, outputSettings, captureDetails.Title, filename);
}
);
uploadUrl = url;
diff --git a/GreenshotPicasaPlugin/PicasaUtils.cs b/GreenshotPicasaPlugin/PicasaUtils.cs
index ca59f1a80..a0c097209 100644
--- a/GreenshotPicasaPlugin/PicasaUtils.cs
+++ b/GreenshotPicasaPlugin/PicasaUtils.cs
@@ -41,7 +41,7 @@ namespace GreenshotPicasaPlugin {
///
/// byte[] with image data
/// PicasaResponse
- public static string UploadToPicasa(Image imageToUpload, OutputSettings outputSettings, string title, string filename) {
+ public static string UploadToPicasa(ISurface surfaceToUpload, OutputSettings outputSettings, string title, string filename) {
OAuthSession oAuth = new OAuthSession(PicasaCredentials.ConsumerKey, PicasaCredentials.ConsumerSecret);
oAuth.BrowserSize = new Size(1020, 590);
oAuth.AccessTokenUrl = "https://www.google.com/accounts/OAuthGetAccessToken";
@@ -67,7 +67,7 @@ namespace GreenshotPicasaPlugin {
try {
IDictionary headers = new Dictionary();
headers.Add("slug", OAuthSession.UrlEncode3986(filename));
- string response = oAuth.MakeOAuthRequest(HTTPMethod.POST, "https://picasaweb.google.com/data/feed/api/user/default/albumid/default", headers, null, null, new ImageContainer(imageToUpload, outputSettings, filename));
+ string response = oAuth.MakeOAuthRequest(HTTPMethod.POST, "https://picasaweb.google.com/data/feed/api/user/default/albumid/default", headers, null, null, new SurfaceContainer(surfaceToUpload, outputSettings, filename));
return ParseResponse(response);
} catch (Exception ex) {
LOG.Error("Upload error: ", ex);
diff --git a/GreenshotPlugin/Core/ClipboardHelper.cs b/GreenshotPlugin/Core/ClipboardHelper.cs
index 9d34ed4c4..5eda939e7 100644
--- a/GreenshotPlugin/Core/ClipboardHelper.cs
+++ b/GreenshotPlugin/Core/ClipboardHelper.cs
@@ -335,10 +335,10 @@ EndSelection:<<<<<<<4
SetDataObject(ido);
}
- private static string getHTMLString(Image image, string filename) {
+ private static string getHTMLString(ISurface surface, string filename) {
string utf8EncodedHTMLString = Encoding.GetEncoding(0).GetString(Encoding.UTF8.GetBytes(HTML_CLIPBOARD_STRING));
- utf8EncodedHTMLString= utf8EncodedHTMLString.Replace("${width}", image.Width.ToString());
- utf8EncodedHTMLString= utf8EncodedHTMLString.Replace("${height}", image.Height.ToString());
+ utf8EncodedHTMLString = utf8EncodedHTMLString.Replace("${width}", surface.Image.Width.ToString());
+ utf8EncodedHTMLString = utf8EncodedHTMLString.Replace("${height}", surface.Image.Height.ToString());
utf8EncodedHTMLString= utf8EncodedHTMLString.Replace("${file}", filename);
StringBuilder sb=new StringBuilder();
sb.Append(utf8EncodedHTMLString);
@@ -349,10 +349,10 @@ EndSelection:<<<<<<<4
return sb.ToString();
}
- private static string getHTMLDataURLString(Image image, MemoryStream pngStream) {
+ private static string getHTMLDataURLString(ISurface surface, MemoryStream pngStream) {
string utf8EncodedHTMLString = Encoding.GetEncoding(0).GetString(Encoding.UTF8.GetBytes(HTML_CLIPBOARD_BASE64_STRING));
- utf8EncodedHTMLString= utf8EncodedHTMLString.Replace("${width}", image.Width.ToString());
- utf8EncodedHTMLString= utf8EncodedHTMLString.Replace("${height}", image.Height.ToString());
+ utf8EncodedHTMLString = utf8EncodedHTMLString.Replace("${width}", surface.Image.Width.ToString());
+ utf8EncodedHTMLString = utf8EncodedHTMLString.Replace("${height}", surface.Image.Height.ToString());
utf8EncodedHTMLString = utf8EncodedHTMLString.Replace("${format}", "png");
utf8EncodedHTMLString = utf8EncodedHTMLString.Replace("${data}", Convert.ToBase64String(pngStream.GetBuffer(),0, (int)pngStream.Length));
StringBuilder sb=new StringBuilder();
@@ -374,7 +374,7 @@ EndSelection:<<<<<<<4
/// For this problem the user should not use the direct paste (=Dib), but select Bitmap
///
private const int BITMAPFILEHEADER_LENGTH = 14;
- public static void SetClipboardData(Image image) {
+ public static void SetClipboardData(ISurface surface) {
DataObject ido = new DataObject();
// This will work for Office and most other applications
@@ -389,7 +389,7 @@ EndSelection:<<<<<<<4
pngStream = new MemoryStream();
// PNG works for Powerpoint
OutputSettings pngOutputSettings = new OutputSettings(OutputFormat.png, 100, false);
- ImageOutput.SaveToStream(image, pngStream, pngOutputSettings);
+ ImageOutput.SaveToStream(surface, pngStream, pngOutputSettings);
pngStream.Seek(0, SeekOrigin.Begin);
}
@@ -402,7 +402,7 @@ EndSelection:<<<<<<<4
bmpStream = new MemoryStream();
// Save image as BMP
OutputSettings bmpOutputSettings = new OutputSettings(OutputFormat.bmp, 100, false);
- ImageOutput.SaveToStream(image, bmpStream, bmpOutputSettings);
+ ImageOutput.SaveToStream(surface, bmpStream, bmpOutputSettings);
imageStream = new MemoryStream();
// Copy the source, but skip the "BITMAPFILEHEADER" which has a size of 14
@@ -414,11 +414,11 @@ EndSelection:<<<<<<<4
// Set the HTML
if (config.ClipboardFormats.Contains(ClipboardFormat.HTML)) {
- string tmpFile = ImageOutput.SaveToTmpFile(image, new OutputSettings(OutputFormat.png), null);
- string html = getHTMLString(image, tmpFile);
+ string tmpFile = ImageOutput.SaveToTmpFile(surface, new OutputSettings(OutputFormat.png), null);
+ string html = getHTMLString(surface, tmpFile);
ido.SetText(html, TextDataFormat.Html);
} else if (config.ClipboardFormats.Contains(ClipboardFormat.HTMLDATAURL)) {
- string html = getHTMLDataURLString(image, pngStream);
+ string html = getHTMLDataURLString(surface, pngStream);
ido.SetText(html, TextDataFormat.Html);
}
} finally {
diff --git a/GreenshotPlugin/Core/ImageOutput.cs b/GreenshotPlugin/Core/ImageOutput.cs
index 78f3cb1fb..a08be7f65 100644
--- a/GreenshotPlugin/Core/ImageOutput.cs
+++ b/GreenshotPlugin/Core/ImageOutput.cs
@@ -74,7 +74,7 @@ namespace GreenshotPlugin.Core {
/// To prevent problems with GDI version of before Windows 7:
/// the stream is checked if it's seekable and if needed a MemoryStream as "cache" is used.
///
- public static void SaveToStream(Image imageToSave, Stream stream, OutputSettings outputSettings) {
+ public static void SaveToStream(ISurface surface, Stream stream, OutputSettings outputSettings) {
ImageFormat imageFormat = null;
bool disposeImage = false;
bool useMemoryStream = false;
@@ -93,6 +93,7 @@ namespace GreenshotPlugin.Core {
case OutputFormat.tiff:
imageFormat = ImageFormat.Tiff;
break;
+ case OutputFormat.greenshot:
case OutputFormat.png:
default:
// Problem with non-seekable streams most likely doesn't happen with Windows 7 (OS Version 6.1 and later)
@@ -109,36 +110,52 @@ namespace GreenshotPlugin.Core {
break;
}
- // Removing transparency if it's not supported
- if (imageFormat != ImageFormat.Png) {
- imageToSave = ImageHelper.Clone(imageToSave, PixelFormat.Format24bppRgb);
+ // check what image we want to save
+ Image imageToSave = null;
+ if (outputSettings.Format == OutputFormat.greenshot) {
+ // We save the image of the surface, this should not be disposed
+ imageToSave = surface.Image;
+ } else {
+ // We create the export image of the surface to save
+ imageToSave = surface.GetImageForExport();
disposeImage = true;
}
-
- // check for color reduction, forced or automatically
- if (conf.OutputFileAutoReduceColors || outputSettings.ReduceColors) {
- WuQuantizer quantizer = new WuQuantizer((Bitmap)imageToSave);
- int colorCount = quantizer.GetColorCount();
- LOG.InfoFormat("Image with format {0} has {1} colors", imageToSave.PixelFormat, colorCount);
- if (outputSettings.ReduceColors || colorCount < 256) {
- try {
- LOG.Info("Reducing colors on bitmap to 255.");
- Image tmpImage = quantizer.GetQuantizedImage(255);
- if (disposeImage) {
- imageToSave.Dispose();
- }
- imageToSave = tmpImage;
- // Make sure the "new" image is disposed
- disposeImage = true;
- } catch (Exception e) {
- LOG.Warn("Error occurred while Quantizing the image, ignoring and using original. Error: ", e);
- }
- }
- } else {
- LOG.Info("Skipping color reduction test, OutputFileAutoReduceColors is set to false.");
- }
-
try {
+
+ // Removing transparency if it's not supported
+ if (imageFormat != ImageFormat.Png && Image.IsAlphaPixelFormat(imageToSave.PixelFormat)) {
+ Image nonAlphaImage = ImageHelper.Clone(imageToSave, PixelFormat.Format24bppRgb);
+ if (disposeImage) {
+ imageToSave.Dispose();
+ }
+ // Make sure the image is disposed!
+ disposeImage = true;
+ imageToSave = nonAlphaImage;
+ }
+
+ // check for color reduction, forced or automatically
+ if (conf.OutputFileAutoReduceColors || outputSettings.ReduceColors) {
+ WuQuantizer quantizer = new WuQuantizer((Bitmap)imageToSave);
+ int colorCount = quantizer.GetColorCount();
+ LOG.InfoFormat("Image with format {0} has {1} colors", imageToSave.PixelFormat, colorCount);
+ if (outputSettings.ReduceColors || colorCount < 256) {
+ try {
+ LOG.Info("Reducing colors on bitmap to 255.");
+ Image tmpImage = quantizer.GetQuantizedImage(255);
+ if (disposeImage) {
+ imageToSave.Dispose();
+ }
+ imageToSave = tmpImage;
+ // Make sure the "new" image is disposed
+ disposeImage = true;
+ } catch (Exception e) {
+ LOG.Warn("Error occurred while Quantizing the image, ignoring and using original. Error: ", e);
+ }
+ }
+ } else {
+ LOG.Info("Skipping color reduction test, OutputFileAutoReduceColors is set to false.");
+ }
+
// Create meta-data
PropertyItem softwareUsedPropertyItem = CreatePropertyItem(PROPERTY_TAG_SOFTWARE_USED, "Greenshot");
if (softwareUsedPropertyItem != null) {
@@ -172,18 +189,27 @@ namespace GreenshotPlugin.Core {
if (!foundEncoder) {
throw new ApplicationException("No JPG encoder found, this should not happen.");
}
- } else if (imageFormat != ImageFormat.Png && Image.IsAlphaPixelFormat(imageToSave.PixelFormat)) {
- // No transparency in target format
- using (Bitmap tmpBitmap = ImageHelper.Clone(imageToSave, PixelFormat.Format24bppRgb)) {
- tmpBitmap.Save(targetStream, imageFormat);
- }
} else {
imageToSave.Save(targetStream, imageFormat);
}
+
// If we used a memory stream, we need to stream the memory stream to the original stream.
if (useMemoryStream) {
memoryStream.WriteTo(stream);
}
+ // Output the surface elements, size and marker to the stream
+ if (outputSettings.Format == OutputFormat.greenshot) {
+ using (MemoryStream tmpStream = new MemoryStream()) {
+ long bytesWritten = surface.SaveElementsToStream(tmpStream);
+ using (BinaryWriter writer = new BinaryWriter(tmpStream)) {
+ writer.Write(bytesWritten);
+ Version v = Assembly.GetExecutingAssembly().GetName().Version;
+ byte[] marker = System.Text.Encoding.ASCII.GetBytes(String.Format("Greenshot{0:00}.{1:00}", v.Major, v.Minor));
+ writer.Write(marker);
+ tmpStream.WriteTo(stream);
+ }
+ }
+ }
} finally {
if (memoryStream != null) {
memoryStream.Dispose();
@@ -195,36 +221,6 @@ namespace GreenshotPlugin.Core {
}
}
- ///
- /// Save a Greenshot surface
- ///
- /// Surface to save
- /// Path to file
- public static void SaveGreenshotSurface(ISurface surface, string fullPath) {
- fullPath = FilenameHelper.MakeFQFilenameSafe(fullPath);
- string path = Path.GetDirectoryName(fullPath);
- // Get output settings from the configuration
- OutputSettings outputSettings = new OutputSettings(OutputFormat.png);
-
- // check whether path exists - if not create it
- DirectoryInfo di = new DirectoryInfo(path);
- if (!di.Exists) {
- Directory.CreateDirectory(di.FullName);
- }
- using (FileStream stream = new FileStream(fullPath, FileMode.Create, FileAccess.Write)) {
- SaveToStream(surface.Image, stream, outputSettings);
- long bytesWritten = surface.SaveElementsToStream(stream);
- using (BinaryWriter writer = new BinaryWriter(stream)) {
- writer.Write(bytesWritten);
- Version v = Assembly.GetExecutingAssembly().GetName().Version;
- string marker = String.Format("Greenshot{0:00}.{1:00}", v.Major, v.Minor);
- using (StreamWriter streamWriter = new StreamWriter(stream)) {
- streamWriter.Write(marker);
- }
- }
- }
- }
-
///
/// Load a Greenshot surface
///
@@ -274,46 +270,6 @@ namespace GreenshotPlugin.Core {
return returnSurface;
}
- ///
- /// Saves image to specific path with specified quality
- ///
- public static void Save(Image image, string fullPath, bool allowOverwrite, OutputSettings outputSettings, bool copyPathToClipboard) {
- fullPath = FilenameHelper.MakeFQFilenameSafe(fullPath);
- string path = Path.GetDirectoryName(fullPath);
-
- // check whether path exists - if not create it
- DirectoryInfo di = new DirectoryInfo(path);
- if (!di.Exists) {
- Directory.CreateDirectory(di.FullName);
- }
- string extension = Path.GetExtension(fullPath);
- if (extension != null && extension.StartsWith(".")) {
- extension = extension.Substring(1);
- }
- OutputFormat format = OutputFormat.png;
- try {
- if (extension != null) {
- format = (OutputFormat)Enum.Parse(typeof(OutputFormat), extension.ToLower());
- }
- } catch (ArgumentException ae) {
- LOG.Warn("Couldn't parse extension: " + extension, ae);
- }
- if (!allowOverwrite && File.Exists(fullPath)) {
- ArgumentException throwingException = new ArgumentException("File '" + fullPath + "' already exists.");
- throwingException.Data.Add("fullPath", fullPath);
- throw throwingException;
- }
- LOG.DebugFormat("Saving image to {0}", fullPath);
- // Create the stream and call SaveToStream
- using (FileStream stream = new FileStream(fullPath, FileMode.Create, FileAccess.Write)) {
- SaveToStream(image, stream, outputSettings);
- }
-
- if (copyPathToClipboard) {
- ClipboardHelper.SetClipboardData(fullPath);
- }
- }
-
///
/// Saves image to specific path with specified quality
///
@@ -332,16 +288,10 @@ namespace GreenshotPlugin.Core {
throwingException.Data.Add("fullPath", fullPath);
throw throwingException;
}
- LOG.DebugFormat("Saving image to {0}", fullPath);
+ LOG.DebugFormat("Saving surface to {0}", fullPath);
// Create the stream and call SaveToStream
- if (outputSettings.Format == OutputFormat.greenshot) {
- SaveGreenshotSurface(surface, fullPath);
- } else {
- using (FileStream stream = new FileStream(fullPath, FileMode.Create, FileAccess.Write)) {
- using (Image image = surface.GetImageForExport()) {
- SaveToStream(image, stream, outputSettings);
- }
- }
+ using (FileStream stream = new FileStream(fullPath, FileMode.Create, FileAccess.Write)) {
+ SaveToStream(surface, stream, outputSettings);
}
if (copyPathToClipboard) {
@@ -367,23 +317,6 @@ namespace GreenshotPlugin.Core {
}
return format;
}
-
- ///
- /// saves img to fullpath
- ///
- /// the image to save
- /// the absolute destination path including file name
- /// true if overwrite is allowed, false if not
- public static void Save(Image img, string fullPath, bool allowOverwrite) {
- OutputFormat format = FormatForFilename(fullPath);
- // Get output settings from the configuration
- OutputSettings outputSettings = new OutputSettings(format);
- if (conf.OutputFilePromptQuality) {
- QualityDialog qualityDialog = new QualityDialog(outputSettings);
- qualityDialog.ShowDialog();
- }
- Save(img, fullPath, allowOverwrite, outputSettings, conf.OutputFileCopyPathToClipboard);
- }
#endregion
#region save-as
@@ -460,7 +393,7 @@ namespace GreenshotPlugin.Core {
///
///
///
- public static string SaveToTmpFile(Image image, OutputSettings outputSettings, string destinationPath) {
+ public static string SaveToTmpFile(ISurface surface, OutputSettings outputSettings, string destinationPath) {
string tmpFile = Path.GetRandomFileName() + "." + outputSettings.Format.ToString();
// Prevent problems with "other characters", which could cause problems
tmpFile = Regex.Replace(tmpFile, @"[^\d\w\.]", "");
@@ -471,7 +404,7 @@ namespace GreenshotPlugin.Core {
LOG.Debug("Creating TMP File : " + tmpPath);
try {
- ImageOutput.Save(image, tmpPath, true, outputSettings, false);
+ ImageOutput.Save(surface, tmpPath, true, outputSettings, false);
tmpFileCache.Add(tmpPath, tmpPath);
} catch (Exception) {
return null;
diff --git a/GreenshotPlugin/Core/NetworkHelper.cs b/GreenshotPlugin/Core/NetworkHelper.cs
index 9adb0089d..5d8695792 100644
--- a/GreenshotPlugin/Core/NetworkHelper.cs
+++ b/GreenshotPlugin/Core/NetworkHelper.cs
@@ -413,13 +413,13 @@ namespace GreenshotPlugin.Core {
///
/// A container to supply images to a Multi-part form data upload
///
- public class ImageContainer : IBinaryContainer {
- private Image image;
+ public class SurfaceContainer : IBinaryContainer {
+ private ISurface surface;
private OutputSettings outputSettings;
private string fileName;
- public ImageContainer(Image image, OutputSettings outputSettings, string filename) {
- this.image = image;
+ public SurfaceContainer(ISurface surface, OutputSettings outputSettings, string filename) {
+ this.surface = surface;
this.outputSettings = outputSettings;
this.fileName = filename;
}
@@ -431,7 +431,7 @@ namespace GreenshotPlugin.Core {
/// string
public string ToBase64String(Base64FormattingOptions formattingOptions) {
using (MemoryStream stream = new MemoryStream()) {
- ImageOutput.SaveToStream(image, stream, outputSettings);
+ ImageOutput.SaveToStream(surface, stream, outputSettings);
return System.Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length, formattingOptions);
}
}
@@ -443,7 +443,7 @@ namespace GreenshotPlugin.Core {
/// byte[]
public byte[] ToByteArray() {
using (MemoryStream stream = new MemoryStream()) {
- ImageOutput.SaveToStream(image, stream, outputSettings);
+ ImageOutput.SaveToStream(surface, stream, outputSettings);
return stream.ToArray();
}
}
@@ -462,7 +462,7 @@ namespace GreenshotPlugin.Core {
"image/" + outputSettings.Format.ToString());
formDataStream.Write(Encoding.UTF8.GetBytes(header), 0, Encoding.UTF8.GetByteCount(header));
- ImageOutput.SaveToStream(image, formDataStream, outputSettings);
+ ImageOutput.SaveToStream(surface, formDataStream, outputSettings);
}
///
@@ -471,7 +471,7 @@ namespace GreenshotPlugin.Core {
///
public void WriteToStream(Stream dataStream) {
// Write the file data directly to the Stream, rather than serializing it to a string.
- ImageOutput.SaveToStream(image, dataStream, outputSettings);
+ ImageOutput.SaveToStream(surface, dataStream, outputSettings);
}
///