User657893922 posted
actually i have copied it from some post. do let me know if things work
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="VB_LoadResizePicture.aspx.vb" Inherits="VB_LoadResizePicture" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:FileUpload id="MyFileUploadControl" Width="400" runat="server" />
<asp:Button runat="server" id="AddAttachmentButton" text="Upload" /><br />
Thumbnail: <asp:Image ID="MyThumbnail" runat="server" /><br /><br />
</form>
</body>
</html>
Imports System.IO 'needed to enable .Delete
Imports System.IO.Path
Imports System.Drawing 'needed to enable Bitmap
Imports System.Drawing.Imaging
Partial Class VB_LoadResizePicture
Inherits System.Web.UI.Page
Protected Sub AddAttachmentButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddAttachmentButton.Click
If MyFileUploadControl.HasFile Then
Dim newfile As String = MyFileUploadControl.FileName
MyFileUploadControl.SaveAs(Server.MapPath("~/somefolder/original") + newfile)
Dim bmp1 As New Bitmap(Server.MapPath("~/somefolder/original") + newfile)
Dim bmpheight As Double = Convert.ToDouble(bmp1.Height)
Dim bmpwidth As Double = Convert.ToDouble(bmp1.Width)
Dim newbmpheight As Integer = Convert.ToInt32(bmpheight / 4)
Dim newbmpwidth As Integer = Convert.ToInt32(bmpwidth / 4)
Dim bmp2 As Bitmap = bmp1.GetThumbnailImage(newbmpwidth, newbmpheight, Nothing, New IntPtr)
bmp2.Save(Server.MapPath("~/somefolder/") + MyFileUploadControl.FileName, ImageFormat.Jpeg)
MyThumbnail.ImageUrl = "somefolder/" + newfile
bmp1.Dispose()
Dim TheFile As FileInfo = New FileInfo(Server.MapPath("~/somefolder/original") + newfile)
If TheFile.Exists Then
File.Delete(Server.MapPath("~/somefolder/original") + newfile)
End If
End If
End Sub
End Class