Noticias Weblogs Foros Wiki Código

RecorteX

318 usuarios y 202 recortes de código
Usuario

Contraseña
Crear cuenta
asp csharp css fechas fichero Flash html imagenes java javascript linux mysql oracle php ruby sql SQLServer vbnet xhtml xml
Top Usuarios
albin (29)
josuebasurto (28)
fjmp76 (27)
juanjo (25)
pedrocaro (9)
AndiXTRM (7)
Joserra (7)
miiglesi (6)
aplyca (5)
moisesmarquez (5)
Top Etiquetas
php (38)
html (23)
javascript (20)
vbnet (20)
java (19)
sql (15)
mysql (13)
csharp (12)
xml (10)
css (8)
imagenes (7)
Flash (7)
xhtml (6)
asp (6)
linux (6)
fechas (6)
SQLServer (5)
oracle (5)
fichero (4)
ruby (4)

Redimensionar una imagen

Redimensionar una imagen
 
		static System.Drawing.Image FixedSize(System.Drawing.Image imgPhoto, int Width, int Height)
		{
			int sourceWidth = imgPhoto.Width;
			int sourceHeight = imgPhoto.Height;
			int sourceX = 0;
			int sourceY = 0;
			int destX = 0;
			int destY = 0; 
 
			float nPercent = 0;
			float nPercentW = 0;
			float nPercentH = 0;
 
			nPercentW = ((float)Width/(float)sourceWidth);
			nPercentH = ((float)Height/(float)sourceHeight);
			if(nPercentH < nPercentW)
			{
				nPercent = nPercentH;
				destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent))/2);
			}
			else
			{
				nPercent = nPercentW;
				destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent))/2);
			}
 
			int destWidth  = (int)(sourceWidth * nPercent);
			int destHeight = (int)(sourceHeight * nPercent);
 
			Bitmap bmPhoto = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
			bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
 
			Graphics grPhoto = Graphics.FromImage(bmPhoto);
			grPhoto.Clear(Color.Transparent);
			grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
 
			grPhoto.DrawImage(imgPhoto, 
				new Rectangle(destX,destY,destWidth,destHeight),
				new Rectangle(sourceX,sourceY,sourceWidth,sourceHeight),
				GraphicsUnit.Pixel);
 
			grPhoto.Dispose();
			return bmPhoto;
		}
 
Identifícate para dejar un comentario.
info@recortex.com - Proyecto: Juanjo Navarro, 2006 - Diseño: Albin