mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 02:37:03 -07:00
Untested performance improvements with uploads, in short the image is directly stored to the upload stream instead of writing a stream to a byte[]. Expecting a small performance improvement, and a lot less memory usage while uploading.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2125 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
c983567827
commit
abe79e65e9
6 changed files with 230 additions and 182 deletions
|
@ -138,42 +138,39 @@ namespace GreenshotImgurPlugin {
|
|||
/// <returns>true if the upload succeeded</returns>
|
||||
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()) {
|
||||
ImageOutput.SaveToStream(image, stream, outputSettings);
|
||||
try {
|
||||
string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
|
||||
ImgurInfo imgurInfo = null;
|
||||
try {
|
||||
string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
|
||||
ImgurInfo imgurInfo = null;
|
||||
|
||||
// Run upload in the background
|
||||
new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("imgur", LangKey.communication_wait),
|
||||
delegate() {
|
||||
imgurInfo = ImgurUtils.UploadToImgur(stream.GetBuffer(), (int)stream.Length, 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);
|
||||
CheckHistory();
|
||||
}
|
||||
);
|
||||
|
||||
imgurInfo.Image = ImageHelper.CreateThumbnail(image, 90, 90);
|
||||
IniConfig.Save();
|
||||
uploadURL = null;
|
||||
try {
|
||||
if (config.UsePageLink) {
|
||||
uploadURL = imgurInfo.Page;
|
||||
Clipboard.SetText(imgurInfo.Page);
|
||||
} else {
|
||||
uploadURL = imgurInfo.Original;
|
||||
Clipboard.SetText(imgurInfo.Original);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.Error("Can't write to clipboard: ", ex);
|
||||
// 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);
|
||||
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);
|
||||
CheckHistory();
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOG.Error(e);
|
||||
MessageBox.Show(Language.GetString("imgur", LangKey.upload_failure) + " " + e.Message);
|
||||
);
|
||||
|
||||
imgurInfo.Image = ImageHelper.CreateThumbnail(image, 90, 90);
|
||||
IniConfig.Save();
|
||||
uploadURL = null;
|
||||
try {
|
||||
if (config.UsePageLink) {
|
||||
uploadURL = imgurInfo.Page;
|
||||
Clipboard.SetText(imgurInfo.Page);
|
||||
} else {
|
||||
uploadURL = imgurInfo.Original;
|
||||
Clipboard.SetText(imgurInfo.Original);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.Error("Can't write to clipboard: ", ex);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOG.Error(e);
|
||||
MessageBox.Show(Language.GetString("imgur", LangKey.upload_failure) + " " + e.Message);
|
||||
}
|
||||
uploadURL = null;
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue