
- Forum
- Programming Talk
- ASP
- Specify Quality for New Bitmap Object
Specify Quality for New Bitmap Object
This is a discussion on Specify Quality for New Bitmap Object within the ASP forums, part of the Programming Talk category; Please bear with me, since I'm an ASP guy, and not a .NET guy. On my site, I dynamically resize/resample ...
-
03-09-2005, 08:06 PM #1someone@somewhere.com Guest
Specify Quality for New Bitmap Object
Please bear with me, since I'm an ASP guy, and not a .NET guy.
On my site, I dynamically resize/resample images so they're not too large.
GetThumbnail resulted in very poor quality, so I create a new
System.Drawing.Image.
It works pretty well for large images that are resized quite a bit, but if
the original image is fairly close to the new size, there's a visible
quality loss.
I've come across some info on how you set this, but I'm not sure how to
incorporate it.
I call the image by using the following example in my .asp page:
<img
src="http://www.devodog.net/image.aspx?src=/cohimages/<%=Character("LogoID")%>.jpg&width=300">
Below is the code in image.aspx. Any suggestions for specifying the
quality?
<% ' import all relevant namespaces %>
<%@ import namespace="System" %>
<%@ import namespace="System.Drawing" %>
<%@ import namespace="System.Drawing.Imaging" %>
<%@ import namespace="System.IO" %>
<script runat="server">
Function NewthumbSize(currentwidth, currentheight)
' Calculate the Size of the New image
dim tempMultiplier as Double
If currentwidth<Request.QueryString("width") Then
tempMultiplier=1
Else
tempMultiplier = Request.QueryString("width") / currentwidth
End If
dim NewSize as New Size(CInt(currentwidth * tempMultiplier),
CInt(currentheight * tempMultiplier))
return NewSize
End Function
Sub sendFile()
' create New image and bitmap objects. Load the image file and put into a
resized bitmap.
dim g as System.Drawing.Image =
System.Drawing.Image.FromFile(server.mappath(request("src")))
dim thisFormat=g.rawformat
dim thumbSize as New size
thumbSize=NewthumbSize(g.width,g.height)
dim imgOutput as New Bitmap(g, thumbSize.width, thumbSize.height)
' Set the contenttype
if thisformat.equals(system.drawing.imaging.imageformat.Gif) then
response.contenttype="image/gif"
else
response.contenttype="image/jpeg"
end if
' send the resized image to the viewer
imgOutput.save(response.outputstream, thisformat) ' output to the user
' tidy up
g.dispose()
imgOutput.dispose()
end sub
Sub sendError()
' if no height, width, src then output "error"
dim imgOutput as New bitmap(120, 120, pixelformat.format24bpprgb)
dim g as graphics = graphics.fromimage(imgOutput) ' create a New graphic
object from the above bmp
g.clear(color.yellow) ' blank the image
g.drawString("ERROR!", New
font("verdana",14,fontstyle.bold),systembrushes.windowtext, New pointF(2,2))
' Set the contenttype
response.contenttype="image/gif"
' send the resized image to the viewer
imgOutput.save(response.outputstream, imageformat.gif) ' output to the user
' tidy up
g.dispose()
imgOutput.dispose()
end sub
</script>
<%
' make sure Nothing has gone to the client
response.clear
if request("src")="" then
call sendError()
else
if file.exists(server.mappath(request("src"))) then
call sendFile()
else
call sendError()
end if
end if
response.end
%>
-
03-10-2005, 04:09 AM #2Adrienne Guest
Re: Specify Quality for New Bitmap Object
Gazing into my crystal ball I observed someone@somewhere.com writing in
news:bcMXd.860$Up2.762@fe01.usenetserver.com:
> Please bear with me, since I'm an ASP guy, and not a .NET guy.
>
And this is a Classic group, not net. You should be looking for something
with a dotnet in its name.
--
Adrienne Boswell
http://www.cavalcade-of-coding.info
Please respond to the group so others can share

Reply With Quote





