基本信息
源码名称:C# 超简单的入门级示例<实例学习>
源码大小:19.88M
文件格式:.rar
开发语言:C#
更新时间:2014-04-30
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 4 元×
微信扫码支付:4 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
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
{
}
}
//第一个参数是邮箱服务器
//第二个参数发件人的帐号
//第三个参数发件人密码
//第四个参数收件人帐号
//第五个参数主题
//第六个参数内容.
}
}