我如何在我的设计表单中转换代码 [英] how can i convert the code in my design form
本文介绍了我如何在我的设计表单中转换代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#Design
#Design
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="convert" runat="server" Text="convert" onclick="convert_Click1" />
<br />
<br />
<br />
<asp:Label ID="uploadlab" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
#code
#code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
public partial class _Default : System.Web.UI.Page
{
static string mailFile;
protected void Page_Load(object sender, EventArgs e)
{
uploadlab.Visible = false;
}
protected void convert_Click1(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
try
{
string path = Server.MapPath("~/photo/") + FileUpload1.FileName;
mailFile = path;
//FileUpload1.SaveAs("C:\\Uploads\\" + FileUpload1.FileName);
FileUpload1.SaveAs(path);
uploadlab.Visible = true;
uploadlab.Text = "Uploaded File Name: " +
FileUpload1.PostedFile.FileName +
"    File Size: " +
FileUpload1.PostedFile.ContentLength +
"    File Type: " +
FileUpload1.PostedFile.ContentType;
}
catch (Exception ex)
{
uploadlab.Text = "Error occured: " + ex.Message.ToString();
}
else
{
uploadlab.Text = "Select a file for upload";
}
}
public class WSC_ConvertImage : WebService
{
[WebMethod]
public bool ConvertImage(byte[] bytInFile, int intToFormat,
out byte[] bytOutFile)
{
bytOutFile = null;
if (bytInFile.Length == 0)
{
// nope.. indicate failure
return false;
}
// string strFileName = mailFile;
string strFileName=Server.MapPath(".")+"\\"+Guid.NewGuid().ToString();
// write the byte array sent to us as a file..
FileStream fsFile = null;
try
{
fsFile = File.Create(strFileName);
}
catch
{
// unable to create input file..
return false;
}
try
{
fsFile.Write(bytInFile, 0, bytInFile.Length);
}
catch
{
// unable to write to the file..
fsFile.Close();
return false;
}
// close the file..
fsFile.Close();
// load the image from the file..
System.Drawing.Image imgInFile = System.Drawing.Image.FromFile(strFileName);
// save to the format specified..
string strOutFileName = strFileName;
switch (intToFormat)
{
case 1: // BMP
strOutFileName = strOutFileName + ".BMP";
imgInFile.Save(strOutFileName, ImageFormat.Bmp);
break;
case 2: // EXIF
strOutFileName = strOutFileName + ".EXIF";
imgInFile.Save(strOutFileName, ImageFormat.Exif);
break;
case 3: // EMF
strOutFileName = strOutFileName + ".EMF";
imgInFile.Save(strOutFileName, ImageFormat.Emf);
break;
case 4: // GIF
strOutFileName = strOutFileName + ".GIF";
imgInFile.Save(strOutFileName, ImageFormat.Gif);
break;
case 5: // ICO
strOutFileName = strOutFileName + ".ICO";
imgInFile.Save(strOutFileName, ImageFormat.Icon);
break;
case 6: // JPEG
strOutFileName = strOutFileName + ".JPG";
imgInFile.Save(strOutFileName, ImageFormat.Jpeg);
break;
case 7: // PNG
strOutFileName = strOutFileName + ".PNG";
imgInFile.Save(strOutFileName, ImageFormat.Png);
break;
case 8: // TIFF
strOutFileName = strOutFileName + ".TIFF";
imgInFile.Save(strOutFileName, ImageFormat.Tiff);
break;
case 9: // WMF
strOutFileName = strOutFileName + ".WMF";
imgInFile.Save(strOutFileName, ImageFormat.Wmf);
break;
default:
strOutFileName = strOutFileName + ".BMP";
imgInFile.Save(strOutFileName, ImageFormat.Bmp);
break;
}
// read the output file..
try
{
fsFile = File.Open(strOutFileName, FileMode.Open, FileAccess.Read);
}
catch
{
// unable to read output file..
return false;
}
// write to the output byte array..
try
{
// create array to read in image file..
int iSize = Convert.ToInt32(fsFile.Length);
bytOutFile = new byte[iSize];
// read the converted image...
fsFile.Read(bytOutFile, 0, iSize);
}
catch
{
// unable to write to the array..
fsFile.Close();
return false;
}
// close the file..
fsFile.Close();
// delete the created files..
try
{
File.Delete(strFileName);
File.Delete(strOutFileName);
}
catch
{
// do nothing..
}
return true;
}
}
}
推荐答案
不要将此问题发布在问题与解决方案"下答案-由于您是从文章中获得代码的,所以(. .NET中的图像格式转换 [ ^ ]),则应使用新邮件底部的邮件"按钮,这将导致向作者发送电子邮件.然后会通知他们您希望与他们交谈.
将其发布到此处依赖于他们的下落"并意识到它是针对他们的.
Don''t post this under Questions & Answers - Since you got the code from an article, (Image Format Conversion in .NET[^]) then you should use the "new message" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.
这篇关于我如何在我的设计表单中转换代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文