Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Displaying folder of images resized before for display (C#)

Displaying folder of images resized before for display (C#)

Displaying folder of images resized before for display (C#)

I have code to show all images in a folder


protected void Page_Load(object sender, EventArgs e)
            string filters = "*.jpg;*.png;*.gif";
            string Path = "~/axisimages/";

            List<String> images = new List<string>();

            foreach (string filter in filters.Split(';'))
                FileInfo[] fit = new DirectoryInfo(this.Server.MapPath(Path)).GetFiles(filter);
                foreach (FileInfo fi in fit)
                    images.Add(String.Format(Path + "/{0}", fi));

            RepeaterImages.DataSource = images;

and then in the aspx


<asp:Repeater ID="RepeaterImages" runat="server">
        <asp:Image ID="Image" runat="server" ImageUrl='<%# Container.DataItem %>' />

Now, I found some code that I believe will resize like I want, but I am unsure where/how/when to implement


public void ResizeImage(double scaleFactor, Stream fromStream, Stream toStream)
            var image = System.Drawing.Image.FromStream(fromStream);
            var newWidth = (int)(image.Width * scaleFactor);
            var newHeight = (int)(image.Height * scaleFactor);
            var thumbnailBitmap = new Bitmap(newWidth, newHeight);

            var thumbnailGraph = Graphics.FromImage(thumbnailBitmap);
            thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;
            thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;
            thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;

            var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
            thumbnailGraph.DrawImage(image, imageRectangle);

            thumbnailBitmap.Save(toStream, image.RawFormat);


I want this all to happen on page_load (it is a folder of security camera motion activated images loaded at 1080p that I would like to resize to 20% for review then we can look at full size if we need to). Would I call ResizeImage inside Page_Load actually inside the inner foreach loop? What would that look like?

Thank you for any help you can give me.


RE: Displaying folder of images resized before for display (C#)

The way we do it is to call a handler(.ashx) and pass the image. The handler has the resize code and passes back the stream to the "src" in the image tag.
This will work BUT, remember, you are getting the full size first then resizing which can take time and resources.
You may want to write a job that monitors the folder with the images in it. And each time an image is added it will be resized and copied to another folder. This way, you can display your "thumbnail" images, then have your front end open the full size image if clicked.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close