Hey, I have the following code, but the only issue with it is that I must load and refresh the webpage in order for it to work.
I'm using a HTA Application to display images, I wish to be able to use JavaScript to send the image URL to the rotating script, then the image/s will be rotated, and then I can reload the images without the need to reload the page or load another one.
Of course I need to use AJAX to send the image URL's to the script. I really don't have a clue how to go about doing this. Here is my test page which has a button and the image:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Image ID="Image1" runat="server" ImageUrl="image.jpg"/>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Rotate_Image" />
</div>
</form>
</body>
</html>
And here is my C# script
using System;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
protected void Rotate_Image(object sender, EventArgs e)
{
//Get the URL variables
string url = Request.QueryString["url"];
string rotate_dir = Request.QueryString["dir"];
//get the path to the image
string path = Server.MapPath(url);
//create an image object from the image in that path
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
//Rotate the image in memory
if (rotate_dir == "clockwise") {
//Rotate is clockwise
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
} else if (rotate_dir == "anticlockwise") {
//Rotate it anti-clockwise
img.RotateFlip(RotateFlipType.Rotate90FlipXY);
}
//Delete the file so the new image can be saved
System.IO.File.Delete(path);
//save the image out to the file
img.Save(path);
//release image file
img.Dispose();
}
}
Thanks for your time guys!