//Namespace Reference using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging;
/// <summary> /// method for resizing an image /// </summary> /// <param name="img">the image to resize</param> /// <param name="percentage">Percentage of change (i.e for 105% of the original provide 105)</param> /// <returns></returns> public Image Resize(Image img, int percentage) { //get the height and width of the image int originalW = img.Width; int originalH = img.Height;
//get the new size based on the percentage change int resizedW = (int)(originalW * percentage); int resizedH = (int)(originalH * percentage);
//create a new Bitmap the size of the new image Bitmap bmp = new Bitmap(resizedW, resizedH); //create a new graphic from the Bitmap Graphics graphic = Graphics.FromImage((Image)bmp); graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; //draw the newly resized image graphic.DrawImage(img, 0, 0, resizedW, resizedH); //dispose and free up the resources graphic.Dispose(); //return the image return (Image)bmp; }
Hvis jeg så smider det i en aspx file, skulle der gerne være stådan at jeg kan <img src="minnetfile.aspx?image=bla.jpg&width=100&height=100">
Men jeg kan ikke få det til at virke... hvad gør jeg forkert?
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.