Nej, det fungere ikke...
Hvis jeg udskifter:
(newWidht/orgWidth)*orgHeight;
med
100;
så virker det fint.
hele filen er:
---
<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Collections" %>
<%@ import Namespace="System.Drawing.Imaging" %>
<script runat="server">
public enum SizeConversionType
{
Type1
}
private const string IMAGE_FOLDER = "";
protected SizeConversionType ConversionType
{
get
{
object o = Request.QueryString["SizeConversionType"];
try
{
return (SizeConversionType)Enum.Parse(typeof(SizeConversionType), o.ToString(), true);
}
catch
{
return SizeConversionType.Type1;
}
}
}
protected string ImageFileName
{
get
{
return (object)Request.QueryString["ImageFileName"] != null ? Request.QueryString["ImageFileName"] : null;
}
}
protected void Page_Load(object sender, System.EventArgs e)
{
string path = Server.MapPath(IMAGE_FOLDER + ImageFileName);
System.Drawing.Image orgImage = System.Drawing.Image.FromFile(path);
int orgWidth = orgImage.Width;
int orgHeight = orgImage.Height;
orgImage.Dispose();
int newWidht = 0;
int newHeigth = 0;
switch(ConversionType)
{
case SizeConversionType.Type1 :
if(orgWidth == 480 && orgHeight == 640)
{
newWidht = 100;
newHeigth = (newWidht/orgWidth)*orgHeight;
}
else if(orgWidth == 640 && orgHeight == 480)
{
newWidht = 100;
newHeigth = newWidht/orgWidth*orgHeight;
}
else
{
newWidht = 100;
newHeigth = newWidht/orgWidth*orgHeight;
}
break;
}
System.Drawing.Image image = ImageResizer.RezizeImage(path, newWidht, newHeigth);
Response.ContentType = "image/jpeg";
image.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
image.Dispose();
}
public class ImageResizer
{
public static System.Drawing.Bitmap RezizeImage(string filePath, int width, int height)
{
System.Drawing.Bitmap bmpOut = null;
try
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(filePath);
bmpOut = new System.Drawing.Bitmap(width, height);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmpOut);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.FillRectangle(System.Drawing.Brushes.White, 0, 0, width, height);
g.DrawImage(bmp, 0, 0, width, height);
bmp.Dispose();
}
catch
{
return null;
}
return bmpOut;
}
}
</script>