mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 09:33:46 -07:00
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:
parent
4e13e13f47
commit
2b8b3c7a62
3 changed files with 22 additions and 9 deletions
|
@ -128,6 +128,7 @@ namespace GreenshotPlugin.Controls {
|
||||||
/// Store all GreenshotControl values to the configuration
|
/// Store all GreenshotControl values to the configuration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected void StoreFields() {
|
protected void StoreFields() {
|
||||||
|
bool iniDirty = false;
|
||||||
foreach (FieldInfo field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
|
foreach (FieldInfo field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
|
||||||
if (!field.FieldType.IsSubclassOf(typeof(Control))) {
|
if (!field.FieldType.IsSubclassOf(typeof(Control))) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -137,7 +138,6 @@ namespace GreenshotPlugin.Controls {
|
||||||
}
|
}
|
||||||
Object controlObject = field.GetValue(this);
|
Object controlObject = field.GetValue(this);
|
||||||
IGreenshotConfigBindable configBindable = controlObject as IGreenshotConfigBindable;
|
IGreenshotConfigBindable configBindable = controlObject as IGreenshotConfigBindable;
|
||||||
bool iniDirty = false;
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(configBindable.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName)) {
|
if (!string.IsNullOrEmpty(configBindable.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName)) {
|
||||||
IniSection section = IniConfig.GetIniSection(configBindable.SectionName);
|
IniSection section = IniConfig.GetIniSection(configBindable.SectionName);
|
||||||
|
@ -160,10 +160,10 @@ namespace GreenshotPlugin.Controls {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (iniDirty) {
|
if (iniDirty) {
|
||||||
IniConfig.Save();
|
IniConfig.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1066,16 +1066,29 @@ namespace GreenshotPlugin.Core {
|
||||||
return newBitmap;
|
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>
|
/// <summary>
|
||||||
/// Scale the bitmap, keeping aspect ratio, but the canvas will always have the specified size.
|
/// Scale the bitmap, keeping aspect ratio, but the canvas will always have the specified size.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceBitmap">Bitmap to scale</param>
|
/// <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="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="newWidth">new width</param>
|
||||||
/// <param name="newHeight">new height</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>
|
/// <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 destX = 0;
|
||||||
int destY = 0;
|
int destY = 0;
|
||||||
|
|
||||||
|
@ -1084,7 +1097,7 @@ namespace GreenshotPlugin.Core {
|
||||||
|
|
||||||
nPercentW = ((float)newWidth / (float)sourceBitmap.Width);
|
nPercentW = ((float)newWidth / (float)sourceBitmap.Width);
|
||||||
nPercentH = ((float)newHeight / (float)sourceBitmap.Height);
|
nPercentH = ((float)newHeight / (float)sourceBitmap.Height);
|
||||||
if (lockAspectRatio) {
|
if (maintainAspectRatio) {
|
||||||
if (nPercentH != 0 && nPercentH < nPercentW) {
|
if (nPercentH != 0 && nPercentH < nPercentW) {
|
||||||
nPercentW = nPercentH;
|
nPercentW = nPercentH;
|
||||||
if (canvasUseNewSize) {
|
if (canvasUseNewSize) {
|
||||||
|
@ -1109,7 +1122,7 @@ namespace GreenshotPlugin.Core {
|
||||||
newHeight = destHeight;
|
newHeight = destHeight;
|
||||||
}
|
}
|
||||||
Bitmap newBitmap = null;
|
Bitmap newBitmap = null;
|
||||||
if (lockAspectRatio && canvasUseNewSize) {
|
if (maintainAspectRatio && canvasUseNewSize) {
|
||||||
newBitmap = CreateEmpty(newWidth, newHeight, sourceBitmap.PixelFormat, backgroundColor, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
newBitmap = CreateEmpty(newWidth, newHeight, sourceBitmap.PixelFormat, backgroundColor, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
||||||
} else {
|
} else {
|
||||||
newBitmap = CreateEmpty(destWidth, destHeight, sourceBitmap.PixelFormat, backgroundColor, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
newBitmap = CreateEmpty(destWidth, destHeight, sourceBitmap.PixelFormat, backgroundColor, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
||||||
|
|
|
@ -338,7 +338,7 @@ namespace Greenshot.IniFile {
|
||||||
private static void SaveInternally(string iniLocation) {
|
private static void SaveInternally(string iniLocation) {
|
||||||
WatchConfigFile(false);
|
WatchConfigFile(false);
|
||||||
|
|
||||||
//LOG.Info("Saving configuration to: " + iniLocation);
|
LOG.Info("Saving configuration to: " + iniLocation);
|
||||||
if (!Directory.Exists(Path.GetDirectoryName(iniLocation))) {
|
if (!Directory.Exists(Path.GetDirectoryName(iniLocation))) {
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(iniLocation));
|
Directory.CreateDirectory(Path.GetDirectoryName(iniLocation));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue