Forum Moderators: open

Message Too Old, No Replies

LoadPicture(PictureName)

Any one use this function?

         

macrost

6:58 pm on Aug 8, 2003 (gmt 0)

10+ Year Member



I have a dynamic website that i'm building and it contains a lot of images of widgets. Now can I use this function to load each picture and dynamically resize it? Or do I have to manually make the pictures the right size?

Thanks!
Mac

mattglet

1:23 pm on Aug 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mac-

you honestly don't ever have to size your pictures. when the page loads, the browser will automatically display them as their full size. although, the advantage of sizing the pictures is that the page will load much quicker due to the browser not having to figure out the size of the picture, rendering the picture, etc. you have already provided the preset values for the image to be displayed at. i hope i described that accurately....

as far as the LoadPicture() function, i have never used it before. interested to see how it works though.

-Matt

markus007

10:31 pm on Aug 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<script runat="server">

Function NewthumbSize(currentwidth, currentheight)


' Calculate the Size of the New image

dim tempMultiplier as Double

if currentheight > currentwidth then ' portrait
tempMultiplier = 150 / currentheight
Else

tempMultiplier = 150 / 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 test as System.Drawing.Image.GetThumbnailImageAbort
dim testb as System.IntPtr
g = 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
' output to the user
g.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

%>

macrost

10:55 pm on Aug 9, 2003 (gmt 0)

10+ Year Member



Matt,
I hear ya, but who is always giving me s#@! about the images on that site i'm developing. ;) Markus, I see now, I have not seen that type of code for images. Thanks for the insight! What's the overhead on this picture object?

Mac

markus007

4:57 am on Aug 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not much overhead, If it gets to be to much overhead, load your most loaded pictures into ram and stream it from there. hint use cache object

mattglet

2:05 pm on Aug 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



haha mac... i'm just saying you need to cut down file size, not pixel size... (photoshop --> save for web)

you are using .net for this one mac?

-Matt

macrost

2:12 am on Aug 11, 2003 (gmt 0)

10+ Year Member



Markus-
Thanks for the tip and the code. I'm sure I'll be using it in the future.
Matt-
Actually I'm using classic asp for that site.

Mac

mattglet

3:08 am on Aug 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mac - IM me when you get a chance... i need some help

TheDave

6:29 am on Aug 12, 2003 (gmt 0)

10+ Year Member



2 questions -

1. Is System.Drawing.Image standard with a normal win2k asp server, without requiring any extra things installed?

2. I glanced across your code, and it's resizing the image, correct? Does it anti-alias the image when it resizes?