I have code to show all images in a folder
and then in the aspx
Now, I found some code that I believe will resize like I want, but I am unsure where/how/when to implement
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.
Willie
Code:
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;
RepeaterImages.DataBind();
}
and then in the aspx
Code:
<asp:Repeater ID="RepeaterImages" runat="server">
<ItemTemplate>
<asp:Image ID="Image" runat="server" ImageUrl='<%# Container.DataItem %>' />
</ItemTemplate>
</asp:Repeater>
Now, I found some code that I believe will resize like I want, but I am unsure where/how/when to implement
Code:
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);
thumbnailGraph.Dispose();
thumbnailBitmap.Dispose();
image.Dispose();
}
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.
Willie