在asp.net中实现图片替换的步骤
<%@Page Language="C#"%>
<%@Import Namespace="System"%>
<%@Import Namespace="System.IO"%>
<%@Import Namespace="System.Drawing"%>
<%@ImportNamespace="System.Drawing.Imaging"%>
<html>
<head>
<script language="C#" runat="server">
//判断
bool imageAbort()
{
return false;
}
void Page_Load(object sender,EventArgs e)
{
System.Drawing.Image SourceImage; //源图片
System.Drawing.Image TargetImage; //目的图片
//图片转换GIF==>JPEG
string SourceFileNameStr=Server.MapPath("123.gif"); //源图片路径
string TargetFileNameStr=Server.MapPath("123.jpg"); //目的图片路径
string TransferFileNameStr=Server.MapPath("640A480.jpg"); //目的图片路径
SourceImage= System.Drawing.Image.FromFile(SourceFileNameStr);
SourceImage.Save(TargetFileNameStr,System.Drawing.Imaging.ImageFormat.Jpeg);
//图处大小转换 TargetFileNameStr的宽为IntWidth,高为IntHeight
SourceImage=System.Drawing.Image.FromFile(TargetFileNameStr);
System.Drawing.Image.GetThumbnailImageAbort myAbort = new System.Drawing.Image.GetThumbnailImageAbort(imageAbort);
int IntWidth=640; //新图片宽
int IntHeight=480; //新图片高
TargetImage = SourceImage.GetThumbnailImage(IntWidth,IntHeight,myAbort,IntPtr.Zero);
FileStream myOutput = new FileStream(TransferFileNameStr,FileMode.Create, FileAccess.Write, FileShare.Write);
TargetImage.Save(myOutput,ImageFormat.Jpeg);
myOutput.Close();
}
</script>
</head>
<body>
</body>
</html>
本文地址:http://www.45fan.com/dnjc/71139.html