Fixed excessive Inifile writing! Added a simple resize method wrapper for Thumbnails.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1770 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-04-11 10:17:05 +00:00
parent 4e13e13f47
commit 2b8b3c7a62
3 changed files with 22 additions and 9 deletions

View file

@ -128,6 +128,7 @@ namespace GreenshotPlugin.Controls {
/// Store all GreenshotControl values to the configuration
/// </summary>
protected void StoreFields() {
bool iniDirty = false;
foreach (FieldInfo field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
if (!field.FieldType.IsSubclassOf(typeof(Control))) {
continue;
@ -137,7 +138,6 @@ namespace GreenshotPlugin.Controls {
}
Object controlObject = field.GetValue(this);
IGreenshotConfigBindable configBindable = controlObject as IGreenshotConfigBindable;
bool iniDirty = false;
if (!string.IsNullOrEmpty(configBindable.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName)) {
IniSection section = IniConfig.GetIniSection(configBindable.SectionName);
@ -160,10 +160,10 @@ namespace GreenshotPlugin.Controls {
}
}
}
}
if (iniDirty) {
IniConfig.Save();
}
}
}
}
}

View file

@ -1066,16 +1066,29 @@ namespace GreenshotPlugin.Core {
return newBitmap;
}
/// <summary>
/// Wrapper for the more complex Resize, this resize could be used for e.g. Thumbnails
/// </summary>
/// <param name="sourceBitmap"></param>
/// <param name="maintainAspectRatio">true to maintain the aspect ratio</param>
/// <param name="newWidth"></param>
/// <param name="newHeight"></param>
/// <returns></returns>
public static Bitmap ResizeBitmap(Bitmap sourceBitmap, bool maintainAspectRatio, int newWidth, int newHeight) {
Point throwAway;
return ResizeBitmap(sourceBitmap, maintainAspectRatio, false, Color.Empty, newWidth, newHeight, out throwAway);
}
/// <summary>
/// Scale the bitmap, keeping aspect ratio, but the canvas will always have the specified size.
/// </summary>
/// <param name="sourceBitmap">Bitmap to scale</param>
/// <param name="lockAspectRatio">true to lock aspect ratio</param>
/// <param name="maintainAspectRatio">true to maintain the aspect ratio</param>
/// <param name="backgroundColor">The color to fill with, or Color.Empty to take the default depending on the pixel format</param>
/// <param name="newWidth">new width</param>
/// <param name="newHeight">new height</param>
/// <returns>a new bitmap with the specified size, the source-bitmap scaled to fit with aspect ratio locked</returns>
public static Bitmap ResizeBitmap(Bitmap sourceBitmap, bool lockAspectRatio, bool canvasUseNewSize, Color backgroundColor, int newWidth, int newHeight, out Point offset) {
public static Bitmap ResizeBitmap(Bitmap sourceBitmap, bool maintainAspectRatio, bool canvasUseNewSize, Color backgroundColor, int newWidth, int newHeight, out Point offset) {
int destX = 0;
int destY = 0;
@ -1084,7 +1097,7 @@ namespace GreenshotPlugin.Core {
nPercentW = ((float)newWidth / (float)sourceBitmap.Width);
nPercentH = ((float)newHeight / (float)sourceBitmap.Height);
if (lockAspectRatio) {
if (maintainAspectRatio) {
if (nPercentH != 0 && nPercentH < nPercentW) {
nPercentW = nPercentH;
if (canvasUseNewSize) {
@ -1109,7 +1122,7 @@ namespace GreenshotPlugin.Core {
newHeight = destHeight;
}
Bitmap newBitmap = null;
if (lockAspectRatio && canvasUseNewSize) {
if (maintainAspectRatio && canvasUseNewSize) {
newBitmap = CreateEmpty(newWidth, newHeight, sourceBitmap.PixelFormat, backgroundColor, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
} else {
newBitmap = CreateEmpty(destWidth, destHeight, sourceBitmap.PixelFormat, backgroundColor, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);

View file

@ -338,7 +338,7 @@ namespace Greenshot.IniFile {
private static void SaveInternally(string iniLocation) {
WatchConfigFile(false);
//LOG.Info("Saving configuration to: " + iniLocation);
LOG.Info("Saving configuration to: " + iniLocation);
if (!Directory.Exists(Path.GetDirectoryName(iniLocation))) {
Directory.CreateDirectory(Path.GetDirectoryName(iniLocation));
}