Ho risolto ho fatto un funzione che mi permette di avere Altezza e Larghezza proporzionate.
Lo condivido con voi magari vi può tornare utile
Codice PHP:
static void Main(string[] args)
{
/*
Esempio
1280*1024
300x300 diventa -> 300*240
verticale 900*1280 = 211*300
*/
int AltezzaImg = 1280;
int LarghezzaImg = 1024;
int MaxValueAltezza = 300;
int MaxValueLarghezza = 300;
int newAltezza;
int newLarghezza;
if (AltezzaImg == LarghezzaImg)
{
/* Quadrata */
newAltezza = MaxValueAltezza;
newLarghezza = MaxValueLarghezza;
}
else
{
if (AltezzaImg > LarghezzaImg)
{
/* Orizzontale */
CalcoloValoreOrizzontale(AltezzaImg, LarghezzaImg, MaxValueAltezza, MaxValueLarghezza);
}
else
{
/* Verticale */
CalcoloValoreVerticale(AltezzaImg, LarghezzaImg, MaxValueAltezza, MaxValueLarghezza);
}
}
}
private static void CalcoloValoreOrizzontale(int A,int L, int MaxA, int MaxV)
{
/* Immagini Orizzontali*/
int z;
z = (MaxA * L) / A;
if (z > MaxA)
{
CalcoloValoreOrizzontale(A, L, MaxA - 1, MaxV);
}
else
{
newAltezza = MaxA;
newLarghezza = z;
}
}
private static void CalcoloValoreVerticale(int A, int L, int MaxA, int MaxV)
{
/* Immagini Verticali*/
int z;
int newAltezza;
int newLarghezza;
z = (MaxV * A) / L;
if (z > MaxV)
{
CalcoloValoreVerticale(A, L, MaxA, MaxV - 1);
}
else
{
newAltezza = MaxA;
newLarghezza = z;
}
}
}