protected void Button1_Click(object sender, EventArgs e)
{
// 根据选中状态初始化值
float pos_t_x = 390.0f;
float pos_t_y = 132.0f;
float pos_b_x = 980.0f;
float pos_b_y = 363.0f; if (RadioButton2.Checked == true)
{
pos_t_x = 430;
pos_t_y = 125;
pos_b_x = 970;
pos_b_y = 380;
} if (RadioButton3.Checked == true)
{
pos_t_x = 75;
pos_t_y = 143;
pos_b_x = 680;
pos_b_y = 380;
} string Filename =string.Empty;
string file = Server.MapPath("") + "\\" + Label1.Text.Replace("/", "\\"); file = file.Replace("image", "card_bg");
file = file.Replace("_all", "");
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(DateTime.Now.Year.ToString());
sb.Append(DateTime.Now.Month.ToString());
sb.Append(DateTime.Now.Day.ToString());
sb.Append(DateTime.Now.Hour.ToString());
sb.Append(DateTime.Now.Minute.ToString());
sb.Append(DateTime.Now.Second.ToString());
sb.Append(".jpg");
Filename = sb.ToString(); //生成缩略图
//原始图片名称
//生成高质量图片名称
string strFile = Server.MapPath("~") + "/card/card_" + Filename; //从文件获取图片对象
//System.Drawing.Image image = System.Drawing.Image.FromStream(hpf.InputStream, true);
System.Drawing.Image image = System.Drawing.Image.FromFile(@file); System.Drawing.Image bitmap = new System.Drawing.Bitmap(1024, 634); //新建bmp图片
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //新建画板
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //制定高质量插值法
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //设置高质量、低速度呈现平滑程度
g.Clear(System.Drawing.Color.White); //清空画布
//在制定位置画图
g.DrawImage(image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), new System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.GraphicsUnit.Pixel);
int fontsize = 20; // 文字大小
// 抬头
//文字水印
System.Drawing.Graphics testGrahpics = System.Drawing.Graphics.FromImage(bitmap);
System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();
string fontpath = Server.MapPath("font/font.ttf");//相对于虚拟目录的字体文件路径
pfc.AddFontFile(fontpath); System.Drawing.Font font = new System.Drawing.Font(pfc.Families[0], fontsize); System.Drawing.Brush brush = new System.Drawing.SolidBrush(ColorTranslator.FromHtml("#E0DEDD")); //分行
string sInput ="尊敬的" + TextBox3.Text.Trim().ToString() + DropDownList1.SelectedItem.Text.ToString() + ":"; //获取输入的水印文字 testGrahpics.DrawString(sInput, font, brush, pos_t_x, pos_t_y); fontsize = 14; // 写落尾---------------------------------------------------------------
testGrahpics = System.Drawing.Graphics.FromImage(bitmap);
font = new System.Drawing.Font(pfc.Families[0], fontsize);
sInput = TextBox4.Text.Trim().ToString() + "致"; //获取输入的水印文字
// 为了保证落尾右侧对其,需要重新计算其X初始坐标
pos_b_x = pos_b_x - (sInput.Length) *(5.0f + (float) fontsize); testGrahpics.DrawString(sInput, font, brush, pos_b_x, pos_b_y);
testGrahpics.Dispose();
//保存缩略图c
try
{
bitmap.Save(strFile, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
Response.Write("保存缩略图失败" + ex.Message);
}
//释放资源
g.Dispose();
bitmap.Dispose();
image.Dispose();
Image1.ImageUrl = "/card/card_" + Filename;
Image1.Visible = true;
HyperLink1.NavigateUrl = "/card/card_" + Filename;
}假的水印在文字周围有水渍一样的东西 求解决办法 ,
还有这个是在读取是损坏了还是在保存时损坏的,求各位大神指点啊
{
// 根据选中状态初始化值
float pos_t_x = 390.0f;
float pos_t_y = 132.0f;
float pos_b_x = 980.0f;
float pos_b_y = 363.0f; if (RadioButton2.Checked == true)
{
pos_t_x = 430;
pos_t_y = 125;
pos_b_x = 970;
pos_b_y = 380;
} if (RadioButton3.Checked == true)
{
pos_t_x = 75;
pos_t_y = 143;
pos_b_x = 680;
pos_b_y = 380;
} string Filename =string.Empty;
string file = Server.MapPath("") + "\\" + Label1.Text.Replace("/", "\\"); file = file.Replace("image", "card_bg");
file = file.Replace("_all", "");
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(DateTime.Now.Year.ToString());
sb.Append(DateTime.Now.Month.ToString());
sb.Append(DateTime.Now.Day.ToString());
sb.Append(DateTime.Now.Hour.ToString());
sb.Append(DateTime.Now.Minute.ToString());
sb.Append(DateTime.Now.Second.ToString());
sb.Append(".jpg");
Filename = sb.ToString(); //生成缩略图
//原始图片名称
//生成高质量图片名称
string strFile = Server.MapPath("~") + "/card/card_" + Filename; //从文件获取图片对象
//System.Drawing.Image image = System.Drawing.Image.FromStream(hpf.InputStream, true);
System.Drawing.Image image = System.Drawing.Image.FromFile(@file); System.Drawing.Image bitmap = new System.Drawing.Bitmap(1024, 634); //新建bmp图片
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //新建画板
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //制定高质量插值法
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //设置高质量、低速度呈现平滑程度
g.Clear(System.Drawing.Color.White); //清空画布
//在制定位置画图
g.DrawImage(image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), new System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.GraphicsUnit.Pixel);
int fontsize = 20; // 文字大小
// 抬头
//文字水印
System.Drawing.Graphics testGrahpics = System.Drawing.Graphics.FromImage(bitmap);
System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();
string fontpath = Server.MapPath("font/font.ttf");//相对于虚拟目录的字体文件路径
pfc.AddFontFile(fontpath); System.Drawing.Font font = new System.Drawing.Font(pfc.Families[0], fontsize); System.Drawing.Brush brush = new System.Drawing.SolidBrush(ColorTranslator.FromHtml("#E0DEDD")); //分行
string sInput ="尊敬的" + TextBox3.Text.Trim().ToString() + DropDownList1.SelectedItem.Text.ToString() + ":"; //获取输入的水印文字 testGrahpics.DrawString(sInput, font, brush, pos_t_x, pos_t_y); fontsize = 14; // 写落尾---------------------------------------------------------------
testGrahpics = System.Drawing.Graphics.FromImage(bitmap);
font = new System.Drawing.Font(pfc.Families[0], fontsize);
sInput = TextBox4.Text.Trim().ToString() + "致"; //获取输入的水印文字
// 为了保证落尾右侧对其,需要重新计算其X初始坐标
pos_b_x = pos_b_x - (sInput.Length) *(5.0f + (float) fontsize); testGrahpics.DrawString(sInput, font, brush, pos_b_x, pos_b_y);
testGrahpics.Dispose();
//保存缩略图c
try
{
bitmap.Save(strFile, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
Response.Write("保存缩略图失败" + ex.Message);
}
//释放资源
g.Dispose();
bitmap.Dispose();
image.Dispose();
Image1.ImageUrl = "/card/card_" + Filename;
Image1.Visible = true;
HyperLink1.NavigateUrl = "/card/card_" + Filename;
}假的水印在文字周围有水渍一样的东西 求解决办法 ,
还有这个是在读取是损坏了还是在保存时损坏的,求各位大神指点啊
解决方案 »
- 关于DateSet的问题
- C中的链表等数据结果如何在C#中实现?
- 关于MessageBox等按钮多语言的问题
- 急求配合socket连接的iocp(完成端口)代码或者资料,200相送。
- C# HttpWebRequest 一个图片URL的怎么获取不COOKIE,在线等
- 下班前的最后一问:有一个ds,里有表dt,表有一栏colm1,对表进行查询判断是否有colm1对应的值是“aaa”,如果有此记录,则显示ok.
- formclosed事件
- winfrom窗体怎么调用 远程数据库Oracle的
- 查询一个时间段内的记录,并显示在datagridview
- Winform.Datagrid: 太复杂,结构不直观,打印功能太弱... PB的Datawindow可做的好多了!!!
- 按钮事件中,如何能够删除动态添加的DataGridView的最后一行(C/S项目)
- 显示上传成功,但是我去文件夹看去木有?
System.Drawing.Image bitmap = new System.Drawing.Bitmap(1024, 634); //新建bmp图片
缩小它,或变成水印的分辨率。说白了就是分辨率的问题
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
System.Drawing.Imaging.ImageCodecInfo codec = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()[1]; System.Drawing.Imaging.EncoderParameters eParams = new System.Drawing.Imaging.EncoderParameters(1);
eParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);