mirror of
https://github.com/greenshot/greenshot
synced 2025-07-14 17:13:44 -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
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue