0
で私の方法を組み合わせ:はねえ、私は私のファイルアップロードに画像のサイズを変更する機能を追加したいが、私は現在のコードでそれを組み込むための方法を見当もつかない画像リサイズ方法
マイコード
protected void UploadButton_Click(object sender, EventArgs e)
{
if (FileUploadControl.HasFile)
{
try
{
string theUserId = Session["UserID"].ToString();
OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=root; Password=commando;");
cn.Open();
OdbcCommand sc = new OdbcCommand(string.Format("SELECT picturepath FROM Pictures WHERE UserID ='{0}'", theUserId), cn);
OdbcDataReader reader = sc.ExecuteReader();
while (reader.Read())
{
if (System.IO.File.Exists(Server.MapPath(Convert.ToString(reader[0]))))
{
System.IO.File.Delete(Server.MapPath(Convert.ToString(reader[0])));
}
}
string filenameDB = Path.GetFileName(FileUploadControl.FileName);
string fileuploadpath = Server.MapPath("~/userdata/" + theUserId + "/uploadedimage/") + Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(fileuploadpath);
string fileuploadpaths = ("~/userdata/" + theUserId + "/uploadedimage/") + filenameDB;
StatusLabel.Text = "Upload status: File uploaded!";
OdbcCommand cmd = new OdbcCommand("UPDATE Pictures SET picturepath ='" + fileuploadpaths + "' WHERE UserId = '" + theUserId + "'", cn);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
}
}
私はちょうどトンの下でそれをすべてしたい今の
protected void Button1_Click(object sender, EventArgs e)
{
if (this.IsValid && this.FileUpload1.HasFile)
{
//Create an ImageElement to wrap up the uploaded image
Neodynamic.WebControls.ImageDraw.ImageElement uploadedImage;
uploadedImage = Neodynamic.WebControls.ImageDraw.ImageElement.FromBinary(this.FileUpload1.FileBytes);
//Create Resize imaging action to apply on the uploaded image
//NOTE: You may apply any of the ImageDraw built-in imaging actions
Neodynamic.WebControls.ImageDraw.Resize actResize = new Neodynamic.WebControls.ImageDraw.Resize();
actResize.Width = 150;
actResize.LockAspectRatio = Neodynamic.WebControls.ImageDraw.LockAspectRatio.WidthBased;
uploadedImage.Actions.Add(actResize);
//Composite the output image by using ImageDraw class
Neodynamic.WebControls.ImageDraw.ImageDraw imgDraw = new Neodynamic.WebControls.ImageDraw.ImageDraw();
//Add uploaded image
imgDraw.Elements.Add(uploadedImage);
//Output image settings...
//For example: save the image in JPEG format always
imgDraw.ImageFormat = Neodynamic.WebControls.ImageDraw.ImageDrawFormat.Jpeg;
imgDraw.JpegCompressionLevel = 90;
//Now, save the output image on disk
string fileName = @"C:\Temp\" + System.IO.Path.GetFileNameWithoutExtension(this.FileUpload1.FileName) + ".jpg";
imgDraw.Save(fileName);
}
}
:コードのサイズを変更
画像彼のワンボタン:
protected void UploadButton_Click(object sender, EventArgs e)
私のコードから。
また、Neodynamic.WebControls.ImageDraw.dllではなく一般的なものを使用する方法があります –