I need to resize an image, before OnUploadComplete event raise.
Is this possible?
it would be better to select the size like: UploadedImageMaxWidth = "800" UploadedImageMaxHeight = "480"
thnak's
Comments: Hi try this put this code on event AjaxFileUpload1.UploadComplete: generateThumbnail(Server.MapPath(".\") & "Repository\Files\", NomeFile) Function: Function generateThumbnail(ByVal filePath As String, ByVal strFileName As String) Try 'Create a new Bitmap Image loading from location of origional file Dim bm As Bitmap = System.Drawing.Image.FromFile(filePath & strFileName) 'Declare Thumbnails Height and Width Dim newWidth As Integer = 200 Dim newHeight As Integer = (newWidth / bm.Width) * bm.Height 'Create the new image as a blank bitmap Dim resized As Bitmap = New Bitmap(newWidth, newHeight) 'Create a new graphics object with the contents of the origional image Dim g As Graphics = Graphics.FromImage(resized) 'Resize graphics object to fit onto the resized image g.DrawImage(bm, New Rectangle(0, 0, resized.Width, resized.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel) 'Get rid of the evidence g.Dispose() 'Create new path and filename for the resized image Dim newStrFileName As String = filePath & strFileName & ".min" 'Save the new image to the same folder as the origional resized.Save(newStrFileName, ImageFormat.Jpeg) Catch ex As Exception Return -1 End Try Return 0 End Function
Is this possible?
it would be better to select the size like: UploadedImageMaxWidth = "800" UploadedImageMaxHeight = "480"
thnak's
Comments: Hi try this put this code on event AjaxFileUpload1.UploadComplete: generateThumbnail(Server.MapPath(".\") & "Repository\Files\", NomeFile) Function: Function generateThumbnail(ByVal filePath As String, ByVal strFileName As String) Try 'Create a new Bitmap Image loading from location of origional file Dim bm As Bitmap = System.Drawing.Image.FromFile(filePath & strFileName) 'Declare Thumbnails Height and Width Dim newWidth As Integer = 200 Dim newHeight As Integer = (newWidth / bm.Width) * bm.Height 'Create the new image as a blank bitmap Dim resized As Bitmap = New Bitmap(newWidth, newHeight) 'Create a new graphics object with the contents of the origional image Dim g As Graphics = Graphics.FromImage(resized) 'Resize graphics object to fit onto the resized image g.DrawImage(bm, New Rectangle(0, 0, resized.Width, resized.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel) 'Get rid of the evidence g.Dispose() 'Create new path and filename for the resized image Dim newStrFileName As String = filePath & strFileName & ".min" 'Save the new image to the same folder as the origional resized.Save(newStrFileName, ImageFormat.Jpeg) Catch ex As Exception Return -1 End Try Return 0 End Function