[longomatch] Add new helper method to scale images
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add new helper method to scale images
- Date: Mon, 7 Jul 2014 11:23:10 +0000 (UTC)
commit 9d4e147a2466b31779953d5947c45ec20f3d1de2
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Tue May 27 18:40:18 2014 +0200
Add new helper method to scale images
LongoMatch.Core/Common/Image.cs | 22 ++++++++++++++++++----
1 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/LongoMatch.Core/Common/Image.cs b/LongoMatch.Core/Common/Image.cs
index 571fd44..658a87f 100644
--- a/LongoMatch.Core/Common/Image.cs
+++ b/LongoMatch.Core/Common/Image.cs
@@ -52,6 +52,18 @@ namespace LongoMatch.Common
Scale (Constants.MAX_THUMBNAIL_SIZE, Constants.MAX_THUMBNAIL_SIZE);
}
+ public void ScaleFactor (int destWidth, int destHeight,
+ out double scaleX, out double scaleY,
+ out Point offset) {
+ int oWidth = 0;
+ int oHeight = 0;
+
+ ComputeScale (Width, Height, destWidth, destHeight, out oWidth, out oHeight);
+ scaleX = (double) oWidth / Width;
+ scaleY = (double) oHeight / Height;
+ offset = new Point ((destWidth - oWidth) / 2, (destHeight - oHeight) / 2);
+ }
+
// this constructor is automatically called during deserialization
public Image (SerializationInfo info, StreamingContext context) {
try {
@@ -165,11 +177,13 @@ namespace LongoMatch.Common
if(inWidth > maxOutWidth || inHeight > maxOutHeight) {
double par = (double)inWidth /(double)inHeight;
+ double outPar = (double)maxOutWidth /(double)maxOutHeight;
- if(inHeight>inWidth)
- outWidth = (int)(outHeight * par);
- else
- outHeight = (int)(outWidth / par);
+ if (outPar > par) {
+ outWidth = Math.Min (maxOutWidth, (int)(outHeight * par));
+ } else {
+ outHeight = Math.Min (maxOutHeight, (int)(outWidth / par));
+ }
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]