mike55 Posted June 14, 2006 Posted June 14, 2006 Hi all I am trying to upload an image, and resize it automatically onto a web server. I have successfully uploaded the file, and I am able to rename it and change the file extention on it. Here is the code that I am using: Dim strLongFilePath As String = fileupload1.PostedFile.FileName Dim intFileNameLength As Integer = InStr(1, StrReverse(strLongFilePath), "\") Dim strFileName As String = Mid(strLongFilePath, (Len(strLongFilePath) - intFileNameLength) + 2) FileUpload1.PostedFile.SaveAs(Server.MapPath("\Samples\") & strFileName) What I am having a problem with is in resizing the file. I have been looking on google but the examples I have found are related to window applications. Any suggestions? Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
mike55 Posted June 15, 2006 Author Posted June 15, 2006 Hi all Here is the code that I am using to resize the image, it fires off without an exception, however, it does not seem to create the new image. Private Sub ResizeImage(ByRef fileName As String, ByVal factor As Integer) Dim img As Bitmap Dim imageResize As Bitmap Dim fs As New FileStream(Server.MapPath("\Samples\") & fileName, FileMode.Open, FileAccess.Read) Dim imgData(fs.Length) As Byte Dim ms As New MemoryStream() fs.Read(imgData, 0, fs.Length) fs.Close() Try img = Image.FromStream(New MemoryStream(imgData)) imageResize = New Bitmap(img, New Size(img.Size.Width * factor, img.Size.Height * factor)) imageResize.Save(ms, Imaging.ImageFormat.Bmp) Catch ex As Exception Stop End Try End Sub Any suggestions? Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
HJB417 Posted June 15, 2006 Posted June 15, 2006 imageResize.Save(ms, Imaging.ImageFormat.Bmp) you're just saving it back to the memory stream. Quote
mike55 Posted June 15, 2006 Author Posted June 15, 2006 So how should I be saving it, I was using img, but that didn't seem logical. Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Administrators PlausiblyDamp Posted June 15, 2006 Administrators Posted June 15, 2006 Theimage has been saved to the MemoryStream. If you want to save it out to a physical file use a FileStream, if you needto do something further with the image then make the function return either ms or an image constructed from ms. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.