using (System.Drawing.Image originalImg = System.Drawing.Image.FromFile(pPath))
{
if (originalImg.Width == imageWidth && originalImg.Height == imageHeight)
{
//return SaveCutPic(pPath, pSavedPath, pPartStartPointX, pPartStartPointY, pPartWidth, pPartHeight,
// pOrigStartPointX, pOrigStartPointY);
}
string filename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
//string filePath = pSavedPath + "\\" + filename;
//pSavedPath = pSavedPath + "newsimages\\" + DateTime.Now.ToString("yyyy_MM_dd");
string curpath = pSavedPath + strPath;
if (isJZ)
{
pSavedPath = curpath + DateTime.Now.ToString("yyMMdd") + "\\HTImages\\" + "200_246\\";
}
else
{
pSavedPath = curpath + DateTime.Now.ToString("yyMMdd") + "\\HTImages\\" + "310_224\\";
}
string filePath = pSavedPath +"\\"+filename;
if (!System.IO.Directory.Exists(pSavedPath))
{
Directory.SetCurrentDirectory(curpath);
if (isJZ)
{
System.IO.Directory.CreateDirectory(DateTime.Now.ToString("yyMMdd") + "\\HTImages\\" + "200_246\\");
}
else
{
System.IO.Directory.CreateDirectory(DateTime.Now.ToString("yyMMdd") + "\\HTImages\\" + "310_224\\");
}
}
Bitmap thumimg =MakeThumbnail(originalImg, imageWidth, imageHeight);
Bitmap partImg = new Bitmap(pPartWidth, pPartHeight); Graphics graphics = Graphics.FromImage(partImg);
Rectangle destRect = new Rectangle(new Point(pPartStartPointX, pPartStartPointY), new Size(pPartWidth, pPartHeight));//目标位置
Rectangle origRect = new Rectangle(new Point(pOrigStartPointX, pOrigStartPointY), new Size(pPartWidth, pPartHeight));//原图位置(默认从原图中截取的图片大小等于目标图片的大小)
///文字水印
Graphics G = Graphics.FromImage(partImg);
//Font f = new Font("Lucida Grande", 6);
//Brush b = new SolidBrush(Color.Gray);
G.Clear(Color.White);
// 指定高质量的双三次插值法。执行预筛选以确保高质量的收缩。此模式可产生质量最高的转换图像。
G.InterpolationMode = InterpolationMode.HighQualityBicubic;
// 指定高质量、低速度呈现。
G.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawImage(thumimg, destRect, origRect, GraphicsUnit.Pixel); //G.DrawString("Xuanye", f, b, 0, 0);
G.Dispose(); originalImg.Dispose();
if (File.Exists(filePath))
{
File.SetAttributes(filePath, FileAttributes.Normal);
File.Delete(filePath);
}
partImg.Save(filePath);
partImg.Dispose();
thumimg.Dispose();
这是按钮的保存方法,多谢大家不吝赐教!
{
if (originalImg.Width == imageWidth && originalImg.Height == imageHeight)
{
//return SaveCutPic(pPath, pSavedPath, pPartStartPointX, pPartStartPointY, pPartWidth, pPartHeight,
// pOrigStartPointX, pOrigStartPointY);
}
string filename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
//string filePath = pSavedPath + "\\" + filename;
//pSavedPath = pSavedPath + "newsimages\\" + DateTime.Now.ToString("yyyy_MM_dd");
string curpath = pSavedPath + strPath;
if (isJZ)
{
pSavedPath = curpath + DateTime.Now.ToString("yyMMdd") + "\\HTImages\\" + "200_246\\";
}
else
{
pSavedPath = curpath + DateTime.Now.ToString("yyMMdd") + "\\HTImages\\" + "310_224\\";
}
string filePath = pSavedPath +"\\"+filename;
if (!System.IO.Directory.Exists(pSavedPath))
{
Directory.SetCurrentDirectory(curpath);
if (isJZ)
{
System.IO.Directory.CreateDirectory(DateTime.Now.ToString("yyMMdd") + "\\HTImages\\" + "200_246\\");
}
else
{
System.IO.Directory.CreateDirectory(DateTime.Now.ToString("yyMMdd") + "\\HTImages\\" + "310_224\\");
}
}
Bitmap thumimg =MakeThumbnail(originalImg, imageWidth, imageHeight);
Bitmap partImg = new Bitmap(pPartWidth, pPartHeight); Graphics graphics = Graphics.FromImage(partImg);
Rectangle destRect = new Rectangle(new Point(pPartStartPointX, pPartStartPointY), new Size(pPartWidth, pPartHeight));//目标位置
Rectangle origRect = new Rectangle(new Point(pOrigStartPointX, pOrigStartPointY), new Size(pPartWidth, pPartHeight));//原图位置(默认从原图中截取的图片大小等于目标图片的大小)
///文字水印
Graphics G = Graphics.FromImage(partImg);
//Font f = new Font("Lucida Grande", 6);
//Brush b = new SolidBrush(Color.Gray);
G.Clear(Color.White);
// 指定高质量的双三次插值法。执行预筛选以确保高质量的收缩。此模式可产生质量最高的转换图像。
G.InterpolationMode = InterpolationMode.HighQualityBicubic;
// 指定高质量、低速度呈现。
G.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawImage(thumimg, destRect, origRect, GraphicsUnit.Pixel); //G.DrawString("Xuanye", f, b, 0, 0);
G.Dispose(); originalImg.Dispose();
if (File.Exists(filePath))
{
File.SetAttributes(filePath, FileAttributes.Normal);
File.Delete(filePath);
}
partImg.Save(filePath);
partImg.Dispose();
thumimg.Dispose();
这是按钮的保存方法,多谢大家不吝赐教!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货