I've looked at the code there, but I don't know if I'm trying to do
something that can't be easily done. All it ever does is hit the Catch
in the Thumbnail routine.
Here's the code I'm trying pull the image with:
'Dim Image As String = Request.QueryString("Image")
Dim Image As String = Session("filename")
If Image Is Nothing Then
Me.ErrorResult()
Return
End If
Dim sSize As String = Request("Size")
Dim Size As Integer = 120
If Not sSize Is Nothing Then
Size = Int32.Parse(sSize)
End If
'Dim Path As String = Server.MapPath(Request.ApplicationPath) +
"\\" + Image
Dim Path As String =
Server.UrlPathEncode("
http://www.mywebsite.com/images/library/downloads/wallpaper/"
+ Image)
Dim bmp As Bitmap = CreateThumbnail(Path, Size, Size)
If bmp Is Nothing Then
Me.ErrorResult()
Return
End If
Dim OutputFilename As String = Nothing
OutputFilename = Request.QueryString("OutputFilename")
If Not OutputFilename Is Nothing Then
If Me.User.Identity.Name = "" Then
' *** Custom error display here
bmp.Dispose()
Me.ErrorResult()
End If
Try
bmp.Save(OutputFilename)
Catch ex As Exception
bmp.Dispose()
Me.ErrorResult()
Return
End Try
End If
' Put user code to initialize the page here
Response.ContentType = "image/jpeg"
bmp.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg)
bmp.Dispose()
The only thing I'm doing differently is creating the filename, and then
where it's looking for a path, I'm giving it a URL.
The other two pieces of code (CreateThumbnail & the Errorresult) are as
they were:
Public Shared Function CreateThumbnail(ByVal lcFilename As String,
ByVal lnWidth As Integer, ByVal lnHeight As Integer) As Bitmap
Dim bmpOut As System.Drawing.Bitmap = Nothing
Try
Dim loBMP As Bitmap = New Bitmap(lcFilename)
Dim loFormat As ImageFormat = loBMP.RawFormat
Dim lnRatio As Decimal
Dim lnNewWidth As Integer = 0
Dim lnNewHeight As Integer = 0
'*** If the image is smaller than a thumbnail just return it
If loBMP.Width < lnWidth And loBMP.Height < lnHeight Then
Return loBMP
End If
If loBMP.Width > loBMP.Height Then
lnRatio = CType(lnWidth / loBMP.Width, Decimal)
lnNewWidth = lnWidth
Dim lnTemp As Decimal = loBMP.Height * lnRatio
lnNewHeight = CType(lnTemp, Integer)
Else
lnRatio = CType(lnHeight / loBMP.Height, Decimal)
lnNewHeight = lnHeight
Dim lnTemp As Decimal = loBMP.Width * lnRatio
lnNewWidth = CType(lnTemp, Integer)
End If
' System.Drawing.Image imgOut =
' loBMP.GetThumbnailImage(lnNewWidth,lnNewHeight,
' null,IntPtr.Zero);
' *** This code creates cleaner (though bigger) thumbnails
and properly
' *** and handles GIF files better by generating a white
background for
' *** transparent images (as opposed to black)
bmpOut = New Bitmap(lnNewWidth, lnNewHeight)
Dim g As Graphics = Graphics.FromImage(bmpOut)
g.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight)
g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight)
loBMP.Dispose()
Catch
Return Nothing
End Try
Return bmpOut
End Function
Private Sub ErrorResult()
Response.Clear()
Response.StatusCode = 404
Response.End()
End Sub
All I really want to do is to put a thumbnail of a mm_yyyy_640.jpg
wallpaper from a sister site into a cell of a table as it's displayed on
the front page of my sales info website.
I'd appreciate any assistance in helping me figure out what's wrong with
what I'm trying to do?
BC