C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




print images in thumbniel format?


Posted Date: 04 Aug 2008      Total Responses: 3

Posted By: lavanya       Member Level: Gold     Points: 1



i am working with .net3.0,and asp with c#

my requirement is ,i have some images on my web form,i want create a context menu with the options "thumbniel","tiles","filmstrip".

how to view images in above formates?





Responses

Author: Nagarajan    04 Aug 2008Member Level: GoldRating:     Points: 6

In the Image Tag specify the URL as below

<img src="ThumbnailGen.aspx?img=xyz.jpg" />


Create a file ThumbnailGen.aspx as below

public class ThumbnailGen : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// get the file name from querystring
string file = Request.QueryString["img"];

// create an image object,
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(file));

// create the actual thumbnail image
// by default the thumbnail is configured to 64x64
System.Drawing.Image thumbnailImage = image.GetThumbnailImage(64, 64, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);

// make a memory stream to work with the image bytes
MemoryStream imageStream = new MemoryStream();

// save the image into the memory stream
thumbnailImage.Save(imageStream, System.Drawing.Imaging.Imageformat.Jpeg);

// make byte array the same size as the image
byte[] imageContent = new Byte[imageStream.Length];

// rewind the memory stream
imageStream.Position = 0;

// load the byte array with the image
imageStream.Read(imageContent, 0, (int)imageStream.Length);

// return byte array to caller with image type
Response.ContentType = "image/jpeg";
Response.BinaryWrite(imageContent);
}

/// <summary>
/// Required, but not used.
/// This is a GetThumbnailImageAbort handler
/// </summary>
/// <returns>true</returns>
public bool ThumbnailCallback()
{
return true; // nothing is done here
}
}


The Thumbnail is configured by default to 64 x 64, if required it can be sent thru querystring along with the img file name and image can be generated as per that.

Happy Coding.



Author: lavanya    05 Aug 2008Member Level: GoldRating:     Points: 4

HAI nagarajan,
in default4.aspx.cs
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(file));
in the above line i am getting an error..
like file not found exception
i have taken in source like this
img src="Default4.aspx?img="~/00759000420.jpg" alt="hai"
help me plz




Author: Nagarajan    12 Aug 2008Member Level: GoldRating:     Points: 4

Sorry Lavanya, for the very delay replay,
i haven't check the forum for a while,
next time pls sent it as a message or to my mailid

problem might be with img url
instead of specifying img src as "~/00759000420.jpg", try giving a path something like, "/website/Images/00759000420.jpg" or a relative path with reference to the current aspx file location.



Post Reply
You must Sign In to post a response.
Next : how to get view state in asp..net using c#
Previous : Crystal Report-Display one record per page
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use