ASP.NET thumbnail creating and saving

G

Guest

Hello friends, how ru all, i have some problem about saving created
thumbnail, following is the code i use for creating thumbnail but thumbnail
was not saved it is on memory which method is used to store created thumbnail
in to hard disk



<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1"
%>
<%@ Import Namespace="System.Drawing.Imaging"%>
<%@ Import Namespace="System.Drawing.image"%>
<script language="VB" runat="server">
Function ThumbnailCallback() as Boolean
return False
end function
Sub Page_Load()
Dim imageurl as string=Request.QueryString("img")
imageurl="/images/" & imageurl
Dim fullsizeimg as system.Drawing.Image
fullsizeimg=System.Drawing.Image.FromFile(Server.M apPath("mug.gif"))
Response.ContentType="image/gif"
'fullsizeimg.save(Response.outputstream,imageforma t.gif)
Dim dummyCallBack as System.Drawing.Image.GetThumbnailImageAbort
dummyCallBack=New system.drawing.image.GetThumbnailimageabort(Addres sOf
ThumbnailCallback)
Dim thumbnailimg as System.Drawing.Image
thumbnailimg=fullsizeimg.GetthumbnailImage(100,100 ,dummyCallBack,IntPtr.Zero)
thumbnailimg.Save(Application.StartupPath&cstrThumbFileName)
End Sub
</script>

pls review it and tell me about he function thanks
 
V

Verde

This works for me. It's C#, but all you need to do is pay attention to the
..NET Framework classes I'm using.

System.IO.FileStream fs = new System.IO.FileStream(pathToFullSizeImage,
System.IO.FileMode.Open, System.IO.FileAccess.Read);

System.Drawing.Image objThumbnail =
System.Drawing.Image.FromStream(fs).GetThumbnailImage(tWidth, tHeight, null,
IntPtr.Zero);

// DO NOT USE THE FOLLOWING LINE; Image.FromFile() keeps the file open. This
is why we open the file via a stream - a stream can be closed.
// System.Drawing.Image objThumbnail =
System.Drawing.Image.FromFile(strFilename).GetThumbnailImage(iWidth,
iHeight, null, IntPtr.Zero);

// Set the ContentType correctly
if (fileType == "JPG" || fileType == "JPEG") {
objThumbnail.Save(pathToThumbnailImage, ImageFormat.Jpeg);
}
else {
objThumbnail.Save(pathToThumbnailImage, ImageFormat.Gif);
}


HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top