实例介绍
【实例简介】
【实例截图】
【核心代码】
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Net.Mail; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } /// <summary> /// 生成缩略图 /// </summary> /// <param name="maxWidth">生成的缩略图最大宽度</param> /// <param name="maxHeight">生成的缩略图最大高度</param> /// <param name="imgFileStream">图片文件流对象</param> /// <param name="savePath">文件保存路径</param> /// <param name="imgFormat">生成图片的格式</param> public void GenerateThumbnail(int maxWidth, int maxHeight, System.IO.Stream imgFileStream, string savePath, System.Drawing.Imaging.ImageFormat imgFormat) { using (var img = System.Drawing.Image.FromStream(imgFileStream)) { var sourceWidth = img.Width; var sourceHeight = img.Height; var thumbWidth = sourceWidth; //要生成的缩略图的宽度 var thumbHeight = sourceHeight; //要生成的缩略图的高度 //计算生成图片的高度和宽度 if (sourceWidth > maxWidth || sourceHeight > maxHeight) { var rateWidth = (double)sourceWidth / maxWidth; var rateHeight = (double)sourceHeight / maxHeight; if (rateWidth > rateHeight) { thumbWidth = maxWidth; thumbHeight = (int)Math.Round(sourceHeight / rateWidth); } else { thumbWidth = (int)Math.Round(sourceWidth / rateHeight); thumbHeight = maxHeight; } } using (var bmp = new System.Drawing.Bitmap(thumbWidth, thumbHeight)) { //从Bitmap创建一个System.Drawing.Graphics对象,用来绘制高质量的缩小图。 using (var gr = System.Drawing.Graphics.FromImage(bmp)) { //设置 System.Drawing.Graphics对象的SmoothingMode属性为HighQuality gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //下面这个也设成高质量 gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; //下面这个设成High gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //把原始图像绘制成上面所设置宽高的缩小图 var rectDestination = new System.Drawing.Rectangle(0, 0, thumbWidth, thumbHeight); gr.DrawImage(img, rectDestination, 0, 0, sourceWidth, sourceHeight, System.Drawing.GraphicsUnit.Pixel); //保存图像 bmp.Save(savePath, imgFormat); } } } } private void button1_Click(object sender, EventArgs e) { //SendMailUseZj(); SendSMTPEMail("smtp.qq.com", "2644783865@qq.com", "362524199005045535a3370501", "542860275@qq.com", "3625", "用asp.net发送邮件,用qq的smtp.qq.com服务器,测试成功"); } //public void SendMailUseZj() //{ // System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); // //msg.To.Add("lcvfb@qq.com"); // msg.To.Add("这里填发给地址如WQER@qq.com"); // // msg.To.Add("b@b.com"); // //可以发送给多人 // //msg.CC.Add("c@c.com"); // //可以抄送给多人 // msg.From = new MailAddress("asdasd@126.com", "SFADSXCVXXV", System.Text.Encoding.UTF8);/* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/ // msg.Subject = "aaaaa" ;//邮件标题 // msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码 // msg.Body = "adsssssssss";//邮件内容 // msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码 // msg.IsBodyHtml =true;//是否是HTML邮件 // //msg.Priority = MailPriority.High;//邮件优先级 // SmtpClient client = new SmtpClient(); // client.Credentials = new System.Net.NetworkCredential("AAAAAAAA@126.com", "77777777"); //发送的邮箱账号密码。这肯定得写你自己的,我用的126 // client.Host = "smtp.126.com"; // object userState = msg; // try // { // //client.SendAsync(msg, userState); // client.Send(msg); // Label1.Text = "发送成功!!"; // } // catch (System.Net.Mail.SmtpException ex) // { // Label1.Text = "发送失败!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";//前台的标签,不用说了吧 // } //} public void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody) { try { System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass); client.DeliveryMethod = SmtpDeliveryMethod.Network; System.Net.Mail.MailMessage message = new MailMessage(strFrom, strto, strSubject, strBody); message.BodyEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = true; client.Send(message); } catch (Exception ex) { throw ex; } finally { } } //第一个参数是邮箱服务器 //第二个参数发件人的帐号 //第三个参数发件人密码 //第四个参数收件人帐号 //第五个参数主题 //第六个参数内容. } }
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论