欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁 > 軟件編程 > C#教程 >

C#圖片添加水印的實(shí)現(xiàn)代碼

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點(diǎn)擊: 次

本文實(shí)例介紹了C#圖片添加水印的實(shí)現(xiàn)方法,可以為圖片加文字水印,及判斷是否是圖片文件,分享給大家供大家參考,具體內(nèi)容如下

效果圖:

以下是HovercWarter類的代碼:

using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace HoverTreeBatch.HovercFrame
{
public class HovercWarter
{
public static Image AddTextToImg(Image image, string text)
{
Bitmap bitmap = new Bitmap(image, image.Width, image.Height);
Graphics g = Graphics.FromImage(bitmap);

float fontSize = 12.0f; //字體大小
float textWidth = text.Length * fontSize; //文本的長度
//下面定義一個矩形區(qū)域,以后在這個矩形里畫上白底黑字
float rectX = 0;
float rectY = 0;
float rectWidth = text.Length * (fontSize + 8);
float rectHeight = fontSize + 8;
//聲明矩形域
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);

Image h_hovercImg = Image.FromStream(ms);

g.Dispose();
bitmap.Dispose();


return h_hovercImg;
}


/// <summary>
/// 根據(jù)文件頭判斷上傳的文件類型
/// </summary>
/// <param name="filePath">filePath是文件的完整路徑 </param>
/// <returns>返回true或false</returns>
public static bool IsPicture(string filePath)
{
try
{
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(fs);
string fileClass;
byte buffer;
buffer = reader.ReadByte();
fileClass = buffer.ToString();
buffer = reader.ReadByte();
fileClass += buffer.ToString();
reader.Close();
fs.Close();
if (fileClass == "255216" || fileClass == "7173" || fileClass == "13780" || fileClass == "6677")
//何問起 hovertree.com
//255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar 
{
return true;
}
else
{
return false;
}
}
catch
{
return false;
}
}
}
}

以上就是C#實(shí)現(xiàn)圖片添加水印的關(guān)鍵性代碼,希望對大家學(xué)習(xí)C#程序設(shè)計(jì)有所幫助。

上一篇:實(shí)例解析C#設(shè)計(jì)模式編程中簡單工廠模式的使用

欄    目:C#教程

下一篇:如何使用C#從word文檔中提取圖片

本文標(biāo)題:C#圖片添加水印的實(shí)現(xiàn)代碼

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6688.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有