欧美日韩精品在线,国内精品久久久久久久久,一级毛片恃级毛片直播,清纯唯美亚洲综合欧美色

asp.net中生成縮略圖并添加版權(quán)_.Net教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:ASP.NET 設(shè)計中的 N 個技巧
asp.net中DataGrid雙行跨列表頭設(shè)計心得! 一、DataGrid的屬性設(shè)置   1. AllowPaging: true   2. PageStyle->Position: TopAndBottom 3. 可選:PageStyle->HorizonAlign: Center(

//定義image類的對象
Drawing.Image image,newimage;
//圖片路徑
protected string imagePath;
//圖片類型
protected string imageType;
//圖片名稱
protected string imageName;

//提供一個回調(diào)方法,用于確定Image對象在執(zhí)行生成縮略圖操作時何時提前取消執(zhí)行
//如果此方法確定 GetThumbnailImage 方法應(yīng)提前停止執(zhí)行,則返回 true;否則返回 false
System.Drawing.Image.GetThumbnailImageAbort callb = null;

private void sm_Click(object sender, System.EventArgs e)
{
string mPath;

if("" != File1.PostedFile.FileName) //File1為上傳文件控件
{
imagePath = File1.PostedFile.FileName;
//取得圖片類型
imageType= imagePath.Substring(imagePath.LastIndexOf(".") 1);
//取得圖片名稱
imageName = imagePath.Substring(imagePath.LastIndexOf("\\") 1);
//判斷是否是JPG或者GIF圖片,這里只是舉個例子,并不一定必須是這兩種圖片
if("jpg" != imageType && "gif" != imageType)
{
Response.Write("<script language='javascript'> alert('對不起!請您選擇jpg或者gif格式的圖片!');</script>");
return;
}
else
{
try
{
//建立虛擬路徑
mPath=Server.MapPath("UploadFiles");
//保存到虛擬路徑
File1.PostedFile.SaveAs(mPath "\\" imageName);

//顯示原圖, imageSource為圖片控件
//imageSource.ImageUrl = "UploadFiles/" imageName;

//為上傳的圖片建立引用
image=System.Drawing.Image.FromFile(mPath "\\" imageName);
//生成縮略圖
newimage=image.GetThumbnailImage(200,200,callb,new System.IntPtr());
//把縮略圖保存到指定的虛擬路徑
newimage.Save(Server.MapPath("UploadFiles") "\\small" imageName);
//釋放image對象占用的資源
image.Dispose();
//釋放newimage對象的資源
newimage.Dispose();
//顯示縮略圖

AddTextToImg ("UploadFiles/" "small" imageName,"Pic Info"); // 在圖片上加入信息說明
Image1.ImageUrl = "UploadFiles/" "small" imageName;

Script.Alert("上傳成功!");
}
catch
{
Script.Alert("上傳失敗!");
}

} // end else
}

// 在圖片上加入自己的信息,
// AddTextToImg (physicPath,"Pic Info");
private void AddTextToImg(string fileName,string text)
{
//string sss = MapPath(fileName);

if ( !File.Exists ( fileName)) {
throw new FileNotFoundException("The file don't exist!");
}

//還需要判斷文件類型是否為圖像類型,這里就不贅述了

System.Drawing.Image image = System.Drawing.Image.FromFile(fileName);//MapPath(fileName));
Bitmap bitmap = new Bitmap(image,image.Width,image.Height);
Graphics g = Graphics.FromImage(bitmap);

float fontSize = 22.0f; //字體大小
float textWidth = text.Length*fontSize; //文本的長度
//下面定義一個矩形區(qū)域,以后在這個矩形里畫上白底黑字
float rectX = 0;
float rectY = 0;
float rectWidth = text.Length*(fontSize 18);
float rectHeight = fontSize 18;
//聲明矩形域
RectangleF textArea = new RectangleF(rectX,rectY,rectWidth,rectHeight);
Font font = new Font("宋體",fontSize);//定義字體
Brush whiteBrush = new SolidBrush(Color.White);
Brush blackBrush = new SolidBrush(Color.Black);
g.FillRectangle(blackBrush,rectX,rectY,rectWidth,rectHeight);
g.DrawString(text,font,whiteBrush,textArea);
MemoryStream ms = new MemoryStream();
//保存為Jpg類型
bitmap.Save(ms,ImageFormat.Jpeg);

//輸出處理后的圖像,這里為了演示方便,我將圖片顯示在頁面中了
/**//* Response.Clear();
Response.ContentType = "image/jpeg";
Response.BinaryWrite( ms.ToArray() );
*/
FileStream fs=new FileStream(fileName, FileMode.OpenOrCreate);//.CreateNew);
fs.Write(ms.ToArray(),0,ms.ToArray().Length);
fs.Close();

Image1.ImageUrl = fileName; // 將圖片顯示在Image控件中
g.Dispose();
bitmap.Dispose();
image.Dispose();
}

分享:asp.net讀取數(shù)據(jù)庫亂碼的解決完全方案
在下面的映射表中加入gb2312 和gbk,就不會有亂碼了,源碼在下面提供一位網(wǎng)友寫的程序改了改 private static void LoadCharsetMap() {

來源:模板無憂//所屬分類:.Net教程/更新時間:2008-08-22
相關(guān).Net教程