さて、私はこのスクリプトを持っています。現時点では、リンクを使用して読み込まれるため、画像の URL は正しいです。しかし、この投稿の件名に示されているエラーが発生しています。
完全なエラーは次のとおりです。
Server Error in '/' Application.
Parameter is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Parameter is not valid.
Source Error:
Line 33: {
Line 34: //Rotate clockwise
Line 35: img.RotateFlip(RotateFlipType.Rotate90FlipNone);
Line 36: } else if (rotate_dir == "anticlockwise")
Line 37: {
Source File: c:\inetpub\wwwroot\nightclub_photography\net\rotate_script.aspx Line: 35
Stack Trace:
[ArgumentException: Parameter is not valid.]
System.Drawing.Image.RotateFlip(RotateFlipType rotateFlipType) +618911
ASP.nightclub_photography_net_rotate_script_aspx.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\nightclub_photography\net\rotate_script.aspx:35
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
System.Web.UI.Control.OnLoad(EventArgs e) +132
System.Web.UI.Control.LoadRecursive() +66
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
Version Information: Microsoft .NET Framework Version:2.0.50727.5472; ASP.NET Version:2.0.50727.5459
これがコードです。画像の回転以外はすべて正常に機能します。
<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Web" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
//string url = Request.QueryString["url"];
string urlStart = @"C:/inetpub/wwwroot/nightclub_photography/data/images/";
//Rotation direction
string rotate_dir = Request.QueryString["dir"];
//Image locations
string str = Request.QueryString["t"];
string[] locs = str.Split(',');
foreach (string item in locs)
{
string url = urlStart + item;
Response.Write(url+"<br />");
//create an image object from the image in that path
System.Drawing.Image tmp = System.Drawing.Image.FromFile(url);
System.Drawing.Image img = tmp;
tmp.Dispose();
//Rotate the image in memory
if (rotate_dir == "clockwise")
{
//Rotate clockwise
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
} else if (rotate_dir == "anticlockwise")
{
//Rotate anti-clockwise
img.RotateFlip(RotateFlipType.Rotate90FlipXY);
}
//Delete the file so the new image can be saved
System.IO.File.Delete(url);
//save the image to the file
img.Save(url);
//release image file
img.Dispose();
}
}
</script>
Response.Write の下のコードを削除すると、スクリプトは次のようになります。これは、URL が正しいことの証拠です。
C:/inetpub/wwwroot/nightclub_photography/data/images/13082013/0/1016158_560614047310285_366565184_n.jpg
C:/inetpub/wwwroot/nightclub_photography/data/images/13082013/0/431824_542683245770032_1870555927_n.jpg