加水印 输入 :图片fileupload +文字textbox +确定==》水印图片保留在服务器+返回path string WaterMake(Fileupload,title){string path=“”;return path;} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://topic.csdn.net/u/20100207/14/62995a22-b8f2-4362-bb26-c0d13882bac1.html?68038 真的是现成的啊。 代码太多了http://topic.csdn.net/u/20100202/13/decda375-6498-4b91-b374-dfabaa61f905.htmlhttp://topic.csdn.net/u/20100112/12/d7b8f909-47b9-439f-9b3c-ae1f57a29292.html /// <summary>/// 获取一个图片按等比例缩小后的大小。/// </summary>/// <param name="maxWidth">需要缩小到的宽度</param>/// <param name="maxHeight">需要缩小到的高度</param>/// <param name="imageOriginalWidth">图片的原始宽度</param>/// <param name="imageOriginalHeight">图片的原始高度</param>/// <returns>返回图片按等比例缩小后的实际大小</returns>public static Size GetNewSize(int maxWidth, int maxHeight, int imageOriginalWidth, int imageOriginalHeight){ double w = 0.0; double h = 0.0; double sw = Convert.ToDouble(imageOriginalWidth); double sh = Convert.ToDouble(imageOriginalHeight); double mw = Convert.ToDouble(maxWidth); double mh = Convert.ToDouble(maxHeight); if (sw < mw && sh < mh) { w = sw; h = sh; } else if ((sw / sh) > (mw / mh)) { w = maxWidth; h = (w * sh) / sw; } else { h = maxHeight; w = (h * sw) / sh; } return new Size(Convert.ToInt32(w), Convert.ToInt32(h));}/// <summary>/// 对给定的一个图片(Image对象)生成一个指定大小的缩略图。/// </summary>/// <param name="originalImage">原始图片</param>/// <param name="thumMaxWidth">缩略图的宽度</param>/// <param name="thumMaxHeight">缩略图的高度</param>/// <returns>返回缩略图的Image对象</returns>public static System.Drawing.Image GetThumbNailImage(System.Drawing.Image originalImage, int thumMaxWidth, int thumMaxHeight){ Size thumRealSize = Size.Empty; System.Drawing.Image newImage = originalImage; Graphics graphics = null; try { thumRealSize = GetNewSize(thumMaxWidth, thumMaxHeight, originalImage.Width, originalImage.Height); newImage = new Bitmap(thumRealSize.Width, thumRealSize.Height); graphics = Graphics.FromImage(newImage); graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.Clear(Color.Transparent); graphics.DrawImage(originalImage, new Rectangle(0, 0, thumRealSize.Width, thumRealSize.Height), new Rectangle(0, 0, originalImage.Width, originalImage.Height), GraphicsUnit.Pixel); } catch { } finally { if (graphics != null) { graphics.Dispose(); graphics = null; } } return newImage;}/// <summary>/// 对给定的一个图片文件生成一个指定大小的缩略图。/// </summary>/// <param name="originalImage">图片的物理文件地址</param>/// <param name="thumMaxWidth">缩略图的宽度</param>/// <param name="thumMaxHeight">缩略图的高度</param>/// <returns>返回缩略图的Image对象</returns>public static System.Drawing.Image GetThumbNailImage(string imageFile, int thumMaxWidth, int thumMaxHeight){ System.Drawing.Image originalImage = null; System.Drawing.Image newImage = null; try { originalImage = System.Drawing.Image.FromFile(imageFile); newImage = GetThumbNailImage(originalImage, thumMaxWidth, thumMaxHeight); } catch { } finally { if (originalImage != null) { originalImage.Dispose(); originalImage = null; } } return newImage;}/// <summary>/// 对给定的一个图片文件生成一个指定大小的缩略图,并将缩略图保存到指定位置。/// </summary>/// <param name="originalImageFile">图片的物理文件地址</param>/// <param name="thumbNailImageFile">缩略图的物理文件地址</param>/// <param name="thumMaxWidth">缩略图的宽度</param>/// <param name="thumMaxHeight">缩略图的高度</param>public static void MakeThumbNail(string originalImageFile, string thumbNailImageFile, int thumMaxWidth, int thumMaxHeight){ System.Drawing.Image newImage = GetThumbNailImage(originalImageFile, thumMaxWidth, thumMaxHeight); try { newImage.Save(thumbNailImageFile, ImageFormat.Jpeg); } catch { } finally { newImage.Dispose(); newImage = null; }}/// <summary>/// 将一个图片的内存流调整为指定大小,并返回调整后的内存流。/// </summary>/// <param name="originalImageStream">原始图片的内存流</param>/// <param name="newWidth">新图片的宽度</param>/// <param name="newHeight">新图片的高度</param>/// <returns>返回调整后的图片的内存流</returns>public static MemoryStream ResizeImage(Stream originalImageStream, int newWidth, int newHeight){ MemoryStream newImageStream = null; System.Drawing.Image newImage = Globals.GetThumbNailImage(System.Drawing.Image.FromStream(originalImageStream), newWidth, newHeight); if (newImage != null) { newImageStream = new MemoryStream(); newImage.Save(newImageStream, ImageFormat.Jpeg); } return newImageStream;} 还是这里效率,看了n个demo,这里最有效 System.Web.UI.WebControlS 命名空间问题求解 让apsnetsessionid不保存在cookie 在这么一需求,请大家各舒己见 .net 用soap扩展类把 soap消息记录到日志文件 谁有手机号码段归属地数据库??发给我一份 马上给分! 页面发布的问题 我写的一个小工具 gridview响应回车事件 我想在网页插入一个Word插件,我该怎么写? 如何在A事件的程序中触发B事件? 请问怎样才可以让时间在网页上动态显示? 关于ajax触发的逻辑,实际开发遇到了问题
真的是现成的啊。
http://topic.csdn.net/u/20100202/13/decda375-6498-4b91-b374-dfabaa61f905.html
http://topic.csdn.net/u/20100112/12/d7b8f909-47b9-439f-9b3c-ae1f57a29292.html
/// <summary>
/// 获取一个图片按等比例缩小后的大小。
/// </summary>
/// <param name="maxWidth">需要缩小到的宽度</param>
/// <param name="maxHeight">需要缩小到的高度</param>
/// <param name="imageOriginalWidth">图片的原始宽度</param>
/// <param name="imageOriginalHeight">图片的原始高度</param>
/// <returns>返回图片按等比例缩小后的实际大小</returns>
public static Size GetNewSize(int maxWidth, int maxHeight, int imageOriginalWidth, int imageOriginalHeight)
{
double w = 0.0;
double h = 0.0;
double sw = Convert.ToDouble(imageOriginalWidth);
double sh = Convert.ToDouble(imageOriginalHeight);
double mw = Convert.ToDouble(maxWidth);
double mh = Convert.ToDouble(maxHeight); if (sw < mw && sh < mh)
{
w = sw;
h = sh;
}
else if ((sw / sh) > (mw / mh))
{
w = maxWidth;
h = (w * sh) / sw;
}
else
{
h = maxHeight;
w = (h * sw) / sh;
} return new Size(Convert.ToInt32(w), Convert.ToInt32(h));
}/// <summary>
/// 对给定的一个图片(Image对象)生成一个指定大小的缩略图。
/// </summary>
/// <param name="originalImage">原始图片</param>
/// <param name="thumMaxWidth">缩略图的宽度</param>
/// <param name="thumMaxHeight">缩略图的高度</param>
/// <returns>返回缩略图的Image对象</returns>
public static System.Drawing.Image GetThumbNailImage(System.Drawing.Image originalImage, int thumMaxWidth, int thumMaxHeight)
{
Size thumRealSize = Size.Empty;
System.Drawing.Image newImage = originalImage;
Graphics graphics = null; try
{
thumRealSize = GetNewSize(thumMaxWidth, thumMaxHeight, originalImage.Width, originalImage.Height);
newImage = new Bitmap(thumRealSize.Width, thumRealSize.Height);
graphics = Graphics.FromImage(newImage); graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.Clear(Color.Transparent); graphics.DrawImage(originalImage, new Rectangle(0, 0, thumRealSize.Width, thumRealSize.Height), new Rectangle(0, 0, originalImage.Width, originalImage.Height), GraphicsUnit.Pixel);
}
catch { }
finally
{
if (graphics != null)
{
graphics.Dispose();
graphics = null;
}
} return newImage;
}
/// <summary>
/// 对给定的一个图片文件生成一个指定大小的缩略图。
/// </summary>
/// <param name="originalImage">图片的物理文件地址</param>
/// <param name="thumMaxWidth">缩略图的宽度</param>
/// <param name="thumMaxHeight">缩略图的高度</param>
/// <returns>返回缩略图的Image对象</returns>
public static System.Drawing.Image GetThumbNailImage(string imageFile, int thumMaxWidth, int thumMaxHeight)
{
System.Drawing.Image originalImage = null;
System.Drawing.Image newImage = null; try
{
originalImage = System.Drawing.Image.FromFile(imageFile);
newImage = GetThumbNailImage(originalImage, thumMaxWidth, thumMaxHeight);
}
catch { }
finally
{
if (originalImage != null)
{
originalImage.Dispose();
originalImage = null;
}
} return newImage;
}
/// <summary>
/// 对给定的一个图片文件生成一个指定大小的缩略图,并将缩略图保存到指定位置。
/// </summary>
/// <param name="originalImageFile">图片的物理文件地址</param>
/// <param name="thumbNailImageFile">缩略图的物理文件地址</param>
/// <param name="thumMaxWidth">缩略图的宽度</param>
/// <param name="thumMaxHeight">缩略图的高度</param>
public static void MakeThumbNail(string originalImageFile, string thumbNailImageFile, int thumMaxWidth, int thumMaxHeight)
{
System.Drawing.Image newImage = GetThumbNailImage(originalImageFile, thumMaxWidth, thumMaxHeight);
try
{
newImage.Save(thumbNailImageFile, ImageFormat.Jpeg);
}
catch
{ }
finally
{
newImage.Dispose();
newImage = null;
}
}
/// <summary>
/// 将一个图片的内存流调整为指定大小,并返回调整后的内存流。
/// </summary>
/// <param name="originalImageStream">原始图片的内存流</param>
/// <param name="newWidth">新图片的宽度</param>
/// <param name="newHeight">新图片的高度</param>
/// <returns>返回调整后的图片的内存流</returns>
public static MemoryStream ResizeImage(Stream originalImageStream, int newWidth, int newHeight)
{
MemoryStream newImageStream = null; System.Drawing.Image newImage = Globals.GetThumbNailImage(System.Drawing.Image.FromStream(originalImageStream), newWidth, newHeight);
if (newImage != null)
{
newImageStream = new MemoryStream();
newImage.Save(newImageStream, ImageFormat.Jpeg);
} return newImageStream;
}