locked
Looking for some good code to resize large images RRS feed

  • Question

  • User135331403 posted

    The code I have degrades the image very badly

    Friday, December 5, 2008 6:44 PM

Answers

All replies

  • User60291871 posted

    take a look at my previous posts here: http://forums.asp.net/t/1079883.aspx

    Hope it works for you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 5, 2008 7:56 PM
  • 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
     
    Friday, December 26, 2008 11:32 PM