troubleshooting Question

Parmater is not valid in Fax thumbnail code - Please Help

Avatar of devnewbee
devnewbee asked on
C#ASP.NETVisual Basic.NET
6 Comments1 Solution589 ViewsLast Modified:
Can anyone look at the attached code and tell me why this error is occuring?

*****

Error Message: Parameter is not valid.
Stack Trace:    at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
  at System.Drawing.Bitmap..ctor(Image original, Int32 width, Int32 height)
  at System.Drawing.Bitmap..ctor(Image original)
  at attachment.ProcessRequest(HttpContext context) in C:\Inetpub\test.org\faxthumbnail.ashx:line 52
  at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
  at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
<%@ WebHandler Language="VB" Class="attachment" %>

Imports System
Imports System.Web

Public Class attachment : Implements IHttpHandler
    
    Const SMALL_MAXDIM As Integer = 200
    Const LARGE_MAXDIM As Integer = 600
    
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        If context.Request.QueryString("id") = "" OrElse Not IsNumeric(context.Request.QueryString("id")) OrElse context.Request.QueryString("page") = "" OrElse Not IsNumeric(context.Request.QueryString("page")) Then
            context.Response.ContentType = "image/jpeg"
            context.Response.Write(Nothing)
        Else
            Dim i As Integer = context.Request.QueryString("page")
            Dim w As Integer
            Dim h As Integer
            Dim sqlCommand As New System.Data.SqlClient.SqlCommand("tg_GetApplicationAttachment", New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("cnBTO").ConnectionString))
            Dim sqlReader As System.Data.SqlClient.SqlDataReader
            Dim buffer() As Byte
            Dim intMaxDimension As Integer = SMALL_MAXDIM
            If context.Request.QueryString("large") = "1" Then
                intMaxDimension = LARGE_MAXDIM
            End If
            sqlCommand.CommandType = CommandType.StoredProcedure
            sqlCommand.Parameters.AddWithValue("@application_attachment_id", context.Request.QueryString("id"))
            sqlCommand.Parameters.AddWithValue("@send_file_body", True)
            sqlCommand.Connection.Open()
            sqlReader = sqlCommand.ExecuteReader()
            sqlReader.Read()
            
            If sqlReader("compressed") Then
                buffer = Utils.DeCompress(sqlReader("file_body"))
            Else
                buffer = sqlReader("file_body")
            End If
            
            sqlReader.Close()
            sqlCommand.Connection.Close()
            
            Dim image As New System.Drawing.Bitmap(New System.IO.MemoryStream(buffer))
            Dim frameDimensions As New System.Drawing.Imaging.FrameDimension(image.FrameDimensionsList(0))
            image.SelectActiveFrame(frameDimensions, i)
            If (image.Height / image.VerticalResolution) > (image.Width / image.HorizontalResolution) Then
                h = intMaxDimension
                w = intMaxDimension * (CDec(image.Width / image.HorizontalResolution) / CDec(image.Height / image.VerticalResolution))
            Else
                h = intMaxDimension * (CDec(image.Height / image.VerticalResolution) / CDec(image.Width / image.HorizontalResolution))
                w = intMaxDimension
            End If
            Dim thumbnail As System.Drawing.Bitmap = New System.Drawing.Bitmap(image).GetThumbnailImage(w, h, Nothing, Nothing)
            context.Response.ContentType = "image/jpeg"
            thumbnail.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
        End If
    
    End Sub
   
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
End Class
ASKER CERTIFIED SOLUTION
SterlingMcClung

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros