Answered by:
Resize image on upload resample picture on ItemInserting

Question
-
User320184449 posted
Can someone please show me how to resample an image before upload using the following code?
Protected Sub UploadPictureUI_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles UploadPictureUI.ItemInserting Dim UploadedFile As FileUpload = CType(UploadPictureUI.FindControl("UploadedFile"), FileUpload) If UploadedFile.PostedFile Is Nothing OrElse String.IsNullOrEmpty(UploadedFile.PostedFile.FileName) OrElse UploadedFile.PostedFile.InputStream Is Nothing Then ShowErrorMessage("No file was uploaded. Please make sure that you've selected a file to upload.") e.Cancel = True Exit Sub End If If UploadedFile.PostedFile.ContentLength > 1048576 Then ShowErrorMessage("This file larger than 1 MB. Please resize your image and try again.") e.Cancel = True Exit Sub End If Dim extension As String = Path.GetExtension(UploadedFile.PostedFile.FileName).ToLower() Dim MIMEType As String = Nothing Select Case extension Case ".gif" MIMEType = "image/gif" Case ".jpg", ".jpeg", ".jpe" MIMEType = "image/jpeg" Case ".png" MIMEType = "image/png" Case Else ShowErrorMessage("Only GIF, JPG, and PNG files can be uploaded to the server.") e.Cancel = True Exit Sub End Select e.Values("MIMEType") = MIMEType Dim imageBytes(UploadedFile.PostedFile.InputStream.Length) As Byte UploadedFile.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length) e.Values("Picture") = imageBytes End Sub
Sunday, February 21, 2010 7:11 AM
Answers
-
User2130758966 posted
I used some image resize code from Rick Strahl's blog in a recent project:
Its really old code and uses a page rather than a httphandler to do the resize but the actual resize code works great.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, February 21, 2010 7:26 PM -
User1364706731 posted
Checkout this
http://stackoverflow.com/questions/254419/asp-net-image-uploading-with-resizing
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, February 22, 2010 5:23 AM
All replies
-
User2130758966 posted
I used some image resize code from Rick Strahl's blog in a recent project:
Its really old code and uses a page rather than a httphandler to do the resize but the actual resize code works great.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, February 21, 2010 7:26 PM -
User1364706731 posted
Checkout this
http://stackoverflow.com/questions/254419/asp-net-image-uploading-with-resizing
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, February 22, 2010 5:23 AM