In my web application I use a AsyncUpload to load the picture of each user to their personal page.
I need to limit the dimensions (height and width) of uploaded images.
How can I validate the height and width of the images before they are loaded? Or convert them to the dimensions I want?
I need images have the dimensions 150x100
I have the following code to validate file type and file size of uploaded images.
foreach (UploadedFile file in LogoUpload.UploadedFiles) { //string filetype = LogoUpload.PostedFile.ContentType; string filetype = file.ContentType; long filesize = file.ContentLength; byte [] input = new byte[filesize - 1]; long maxFileSize = 1024; if (filesize > maxFileSize) { base.OnUIValidation("The file is too big."); return; } string[] acceptedFileTypes = new string[3]; acceptedFileTypes[0] = "image/jpg"; acceptedFileTypes[1] = "image/jpeg"; acceptedFileTypes[2] = "image/jpeg"; bool acceptFile = false; //should we accept the file? for (int i = 0; i <= 2; i++) { if (filetype == acceptedFileTypes[i]) { //accept the file, yay! acceptFile = true; } }