this is my aspx code:
<asp:FileUpload ID="FileUpload2" runat="server" Width="500px" />
<asp:Button ID="btnUploadImg" runat="server" onclick="btnNahrajObrazek_Click" Text="Nahrát obrázek" Height="35px" Width="150px" />
and this is my code behind:
protected void btnUploadImg_Click(object sender, EventArgs e)
{
string input = Request.Url.AbsoluteUri;
string output = input.Substring(input.IndexOf('=') + 1);
string fileName = Path.GetFileName(FileUpload2.PostedFile.FileName);
int width = 800;
int height = 600;
Stream stream = FileUpload2.PostedFile.InputStream;
Bitmap image = new Bitmap(stream);
Bitmap target = new Bitmap(width, height);
Graphics graphic = Graphics.FromImage(target);
graphic.DrawImage(image, 0, 0, width, height);
target.Save(Server.MapPath("~/Uploads/" + output + "/") + fileName);
}
I'd like to keep aspect ratio of images being uploaded, so I need to set only width or set width like 100% and height 400 or something like that ? But don't know to do it.
If this is not possible, image cropping will be good enought, but I'd like first better.
Thanks in advance!