locked
strange behaviour RRS feed

  • Question

  • User2045693258 posted

    i use the code below to upload an image and resize it. up until about a month ago it worked ok, now after i upload an image the pagereloads in postback as the html source. does thing ring any bells with anyone as to why this would happen. i'm using asp.net 2.0. the weird thing is that the image actually resizes and uploads, just on postback i get the html page source and not my webpage - ie the rendered html code as if i was looking at view source.


    Imports System.Drawing
    Imports System.Drawing.Imaging
    Imports System.Drawing.Drawing2D
    Imports System.Drawing.Font
    Imports System.IO


    Partial Class testupload
        Inherits System.Web.UI.Page

        Protected Sub filebut_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles filebut.Click
            Dim originalImg As Bitmap
            Dim newHeight As Int32
            originalImg = New Bitmap(FileUpload1.FileContent)
            Dim origWidth As Int32 = originalImg.Width
            Dim origHeight As Int32 = originalImg.Height
            Dim sngRatio As Double
            sngRatio = origWidth / origHeight
            newHeight = 200 / sngRatio
            Dim newImg As Bitmap = New Bitmap(200, newHeight)
            Dim oGraphics As Graphics = Graphics.FromImage(newImg)
            oGraphics.SmoothingMode = SmoothingMode.AntiAlias
            oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic
            oGraphics.DrawImage(originalImg, 0, 0, 200, newHeight)
            Const intQuality = 100
            Dim codecs() As ImageCodecInfo = ImageCodecInfo.GetImageEncoders()
            Dim iciInfo As ImageCodecInfo
            Dim item As ImageCodecInfo
            For Each item In codecs
                If (item.MimeType = "image/jpeg") Then iciInfo = item
            Next
            Dim ep As EncoderParameters = New EncoderParameters()
            ep.Param(0) = New System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, intQuality)
            Response.ContentType = "image/jpeg"
            newImg.Save("domainpathgohere\" & FileUpload1.FileName, iciInfo, ep)
        End Sub
    End Class

    Wednesday, August 12, 2009 11:56 AM

Answers

  • User1863286578 posted

     check the image size

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 13, 2009 10:21 AM

All replies

  • User1863286578 posted

     check the image size

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 13, 2009 10:21 AM
  • User1007942699 posted

    Salamo Alikom Smile 

    to solve this issue please comment out the following line:

    //Response.ContentType = "image/jpeg"

    Regards

    Sayed Moawad

    Sunday, August 30, 2009 6:40 AM