Hi all,
I create a Thumbnail.aspx page for creating thumbnails on the fly, the problem is that the page works perfectly on any ASP.NET Application but not when i use it in my custom DDN Module and I don't understand why.
This is the page code:
Partial Public Class ThumbnailInherits System.Web.UI.PagePrivate Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.LoadDim strPath As String = Request.QueryString("p")Dim strImg As String = Request.QueryString("i")Dim intW As Integer = Request.QueryString("w")Dim intH As Integer = Request.QueryString("h")'original image
Dim objImage As System.Drawing.Image = New Bitmap(Server.MapPath(strPath & strImg))Dim intImgW As Integer = objImage.WidthDim intImgH As Integer = objImage.Height'new width and height
Dim intThumbW As Integer
Dim intThumbH As Integer
If intImgW >= intW And intImgH >= intH Then
If intImgW > intImgH Then
intThumbW = intW
intThumbH = (intH * intImgH) / intImgW
Else
intThumbW = (intH / intImgH) * intImgW
intThumbH = intH
End If
ElseIf intImgW <= intW And intImgH <= intH Then
intThumbW = intImgW
intThumbH = intImgH
ElseIf intImgW >= intW And intImgH <= intH Then
intThumbW = intW
intThumbH = (intH * intImgH) / intImgW
ElseIf intImgW <= intW And intImgH >= intH Then
intThumbW = (intH / intImgH) * intImgW
intThumbH = intH
End If
'miniature
Dim objThumbImage As System.Drawing.Image'image codec info
Dim myImageCodecInfo As System.Drawing.Imaging.ImageCodecInfoDim Encoders As System.Drawing.Imaging.ImageCodecInfo() = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()For i As Integer = 0 To (Encoders.Length - 1)If (Encoders(i).MimeType = "image/jpeg") Then
myImageCodecInfo = Encoders(i)
End If
Next i'parameters
myEncoderParameters =
Dim myEncoderParameters As System.Drawing.Imaging.EncoderParametersNew System.Drawing.Imaging.EncoderParameters(1)'encoder quality, value compression
Dim myEncoderQuality As System.Drawing.Imaging.Encoder = System.Drawing.Imaging.Encoder.QualityDim Compression As Long
If Trim(Request.QueryString("c")) = "" Then
Compression = 100
Else
Compression =
Long.Parse(Request.QueryString("c"))End If
'quality parameter
myEncoderParameterQuality =
Dim myEncoderParameterQuality As System.Drawing.Imaging.EncoderParameterNew System.Drawing.Imaging.EncoderParameter(myEncoderQuality, Compression)'add quality parameter to parameters
myEncoderParameters.Param(0) = myEncoderParameterQuality
callback =
objThumbImage = objImage.GetThumbnailImage(intThumbW, intThumbH, callback, IntPtr.Zero)
Dim callback As System.Drawing.Image.GetThumbnailImageAbortNew System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)'crop --------------------------------------------------------------------------------------------------------------------
'Dim objDrawImage As New System.Drawing.Bitmap(intW, intH, PixelFormat.Format24bppRgb)
'Dim objGraphics As Graphics = Graphics.FromImage(objDrawImage)
'objGraphics.CompositingQuality = CompositingQuality.HighQuality
'objGraphics.SmoothingMode = SmoothingMode.AntiAlias
'objGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic
'Dim intXSize As Integer = objThumbImage.Width - 1
'Dim intYSize As Integer = objThumbImage.Height - 1
'Dim intHalfWidth As Integer = intXSize / 2
'Dim intHalfHeight As Integer = intYSize / 2
'Dim X As Integer = intHalfWidth - (intW / 2)
'Dim Y As Integer = intHalfHeight - (intH / 2)
'objGraphics.DrawImage(objThumbImage, New Rectangle(0, 0, intW, intH), New Rectangle(X, Y, intW, intH), GraphicsUnit.Pixel)
'objThumbImage.Dispose()
'-------------------------------------------------------------------------------------------------------------------------
Response.ContentType =
"image/jpeg"
'objDrawImage.Save(Response.OutputStream, myImageCodecInfo, myEncoderParameters)
objThumbImage.Save(Response.OutputStream, myImageCodecInfo, myEncoderParameters)
objImage.Dispose()
objThumbImage.Dispose()
'objGraphics.Dispose()
'objDrawImage.Dispose()
Maybe the problem is the use of AJAX in my module?
Thank you for your help! :-)
End Sub