急求缩略图方法 .... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 试试这个 public static void MakeSmallImg(System.IO.Stream fromFileStream, string fileSaveUrl, Double templateWidth, Double templateHeight) { System.Drawing.Image myImage = System.Drawing.Image.FromStream(fromFileStream, true); System.Double newWidth = myImage.Width, newHeight = myImage.Height; if (myImage.Width > myImage.Height || myImage.Width == myImage.Height) { if (myImage.Width > templateWidth) { //宽按模版,高按比例缩放 newWidth = templateWidth; newHeight = myImage.Height * (newWidth / myImage.Width); } } //高大于模版的竖图 else { if (myImage.Height > templateHeight) { //高按模版,宽按比例缩放 newHeight = templateHeight; newWidth = myImage.Width * (newHeight / myImage.Height); } } System.Drawing.Size mySize = new Size((int)newWidth, (int)newHeight); System.Drawing.Image bitmap = new System.Drawing.Bitmap(mySize.Width, mySize.Height); 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(Color.White); g.DrawImage(myImage, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), new System.Drawing.Rectangle(0, 0, myImage.Width, myImage.Height), System.Drawing.GraphicsUnit.Pixel); //保存缩略图 bitmap.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg); g.Dispose(); myImage.Dispose(); bitmap.Dispose(); } http://www.wave12.com/web/home.asp缩略图水印组件wsImage3.5 为什么我的WPF控件就不美嘞? 最近在学习c#的一些简单的知识!下面知识不是很理解 ,希望高手们帮哈忙哦! 明天要去大连华信面试了 哪位帮个忙 VS2005调试winform程序,添加断点提示“当前不会命中断点 还没有为该文档加载任何符号” 关于arraylist的问题。 c# 调用vc的DLL问题 数据库中的字段问题! Updater Application Blocks! sqlserver中触发器的问题!急! C#中如何实现 查找下一项 功能? sql问题 高分求助:有关网页抓取的若干问题
public static void MakeSmallImg(System.IO.Stream fromFileStream, string fileSaveUrl, Double templateWidth, Double templateHeight)
{
System.Drawing.Image myImage = System.Drawing.Image.FromStream(fromFileStream, true);
System.Double newWidth = myImage.Width, newHeight = myImage.Height;
if (myImage.Width > myImage.Height || myImage.Width == myImage.Height)
{
if (myImage.Width > templateWidth)
{
//宽按模版,高按比例缩放 newWidth = templateWidth;
newHeight = myImage.Height * (newWidth / myImage.Width);
}
}
//高大于模版的竖图
else
{
if (myImage.Height > templateHeight)
{
//高按模版,宽按比例缩放 newHeight = templateHeight;
newWidth = myImage.Width * (newHeight / myImage.Height);
}
} System.Drawing.Size mySize = new Size((int)newWidth, (int)newHeight);
System.Drawing.Image bitmap = new System.Drawing.Bitmap(mySize.Width, mySize.Height);
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(Color.White);
g.DrawImage(myImage, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
new System.Drawing.Rectangle(0, 0, myImage.Width, myImage.Height),
System.Drawing.GraphicsUnit.Pixel); //保存缩略图 bitmap.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg); g.Dispose();
myImage.Dispose();
bitmap.Dispose();
}