本文借助vs
實現過程
代碼如下
upfile
<%@ Page Language=
<!DOCTYPE html PUBLIC
<html xmlns=
<head runat=
<title>無標題頁</title>
</head>
<body>
<form id=
<div>
<asp:FileUpload ID=
<asp:Button ID=
<asp:Label ID=
</form>
</body>
</html>
upfile
using System;
using System
using System
using System
using System
using System
using System
using System
using System
using System
using System
public partial class upfile_upfile : System
{
protected void Page_Load(object sender
{ }
protected void Button
{
if (FileUpload
{
string fileContentType = FileUpload
if (fileContentType ==
{
string name = FileUpload
FileInfo file = new FileInfo(name);
string fileName = file
string fileName_s =
string fileName_sy =
string fileName_syp =
string webFilePath = Server
string webFilePath_s = Server
string webFilePath_sy = Server
string webFilePath_syp = Server
string webFilePath_sypf = Server
if (!File
{
try
{
FileUpload
AddShuiYinWord(webFilePath
AddShuiYinPic(webFilePath
MakeThumbnail(webFilePath
Label
}
catch (Exception ex)
{
Label
}
}
else
{
Label
}
}
else
{
Label
}
}
}
/**//// <summary>
/// 生成縮略圖
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <param name=
/// <param name=
public static void MakeThumbnail(string originalImagePath
{
System
int towidth = width;
int toheight = height;
int x =
int y =
int ow = originalImage
int oh = originalImage
switch (mode)
{
case
break;
case
toheight = originalImage
break;
case
towidth = originalImage
break;
case
if ((double)originalImage
{
oh = originalImage
ow = originalImage
y =
x = (originalImage
}
else
{
ow = originalImage
oh = originalImage
x =
y = (originalImage
}
break;
default:
break;
}
//新建一個bmp圖片
System
//新建一個畫板
System
//設置高質量插值法
g
//設置高質量
g
//清空畫布並以透明背景色填充
g
//在指定位置並且按指定大小繪制原圖片的指定部分
g
new System
System
try
{
//以jpg格式保存縮略圖
bitmap
}
catch (System
{
throw e;
}
finally
{
originalImage
bitmap
g
}
}
/**//// <summary>
/// 在圖片上增加文字水印
/// </summary>
/// <param name=
/// <param name=
protected void AddShuiYinWord(string Path
{
string addText =
System
System
g
System
System
g
g
image
image
}
/**//// <summary>
/// 在圖片上生成圖片水印
/// </summary>
/// <param name=
/// <param name=
/// <param name=
protected void AddShuiYinPic(string Path
{
System
System
System
g
g
image
image
}
}
From:http://tw.wingwit.com/Article/program/ASP/201311/21767.html