求网站图片处理程序 收缩此栏目
-
- 价格:¥100
- 任务编号:5918
- 任务分类:编程
- 开始时间:2008-04-05 19:09:49
- 结束时间:2008-04-09 19:09:49
- 任务状态:任务已圆满结束
中标稿件:会员koorise的1822116号稿 件[2008-10-13 05:27:22] 投票时时彩
中标模式单人中标模式,一人独享赏金。
赏金申明本站已经收到客户的汇款,确定此任务总金额的80%可以支付 给被客户选中的会员。
版权声明稿件如果被客户选中,在完成赏金支付后,该作品的全部知识产权自动转移给客户;如果没有被选中,可自行处理。
当前任务已有:2303人关注 11人报名 12个稿件 8篇交流 备选稿件(0)个 橱窗方式浏览
稿件编号:1822116号
- koorise
- 等 级:猪二戒
- 信用值:

- 能力值:


发布者已浏览查看所有交稿 时间:2008/04/09 18:20:24 评论:0条票数:3
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Drawing.Imaging;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUpLoad_Click(object sender, EventArgs e)
{
Random n = new Random();
string str="~/" +n.Next(100000).ToString()+ FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.IndexOf("."));
FileUpload1.SaveAs(Server.MapPath(str));
myGetThumbnailImage(Server.MapPath(str), @"D:\Project\ImageEdit\84283-1.jpg", 120,120, "white");
}
/// <summary>
/// 判断图片大小 Quality(upload)
/// </summary>
/// <param name="upLoad">控件</param>
/// <returns></returns>
public Boolean Quality(FileUpload upLoad)
{
if (upLoad.PostedFile.ContentLength > 50000)
{
return false;
}
else
{
return true;
}
}
public Boolean Size(string path)
{
System.Drawing.Image myThumbnail = System.Drawing.Image.FromFile(path);
if ((myThumbnail.Width > 550) && (myThumbnail.Height > 412.5))
{
System.Drawing.Image copyImage = myThumbnail.GetThumbnailImage(550, 412, null, IntPtr.Zero);
return false;
}
else
{
return true;
}
}
/// </summary>
/// <param name="SourceFile">文件在服务器上的物理地址</param>
/// <param name="strSavePathFile">保存在服务器上的路径</param>
/// <param name="ThumbWidth">宽度</param>
/// <param name="ThumbHeight">高度</param>
/// <param name="BgColor">背景</param>
public static void myGetThumbnailImage(string SourceFile, string strSavePathFile, int ThumbWidth, int ThumbHeight, string BgColor)
{
System.Drawing.Image oImg = System.Drawing.Image.FromFile(SourceFile);
//小图
int intwidth, intheight;
if (oImg.Width > oImg.Height)
{
if (oImg.Width > ThumbWidth)
{
intwidth = ThumbWidth;
intheight = (oImg.Height * ThumbWidth) / oImg.Width;
}
else
{
intwidth = oImg.Width;
intheight = oImg.Height;
}
}
else
{
if (oImg.Height > ThumbHeight)
{
intwidth = (oImg.Width * ThumbHeight) / oImg.Height; intheight = ThumbHeight;
}
else
{
intwidth = oImg.Width; intheight = oImg.Height;
}
}
//构造一个指定宽高的Bitmap
Bitmap bitmay = new Bitmap(intwidth, intheight);
Graphics g = Graphics.FromImage(bitmay);
Color myColor;
if (BgColor == null) myColor = Color.FromName("white");
else
myColor = Color.FromName(BgColor);
//用指定的颜色填充Bitmap
g.Clear(myColor);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
//开始画图
g.DrawImage(oImg, new Rectangle(0, 0, intwidth, intheight), new Rectangle(0, 0, oImg.Width, oImg.Height), GraphicsUnit.Pixel);
//bitmay.Save(strSavePathFile, System.Drawing.Imaging.ImageFormat.Jpeg);
KiSaveAsJPEG(bitmay, @"D:\Project\ImageEdit\1.jpg", 50);
g.Dispose();
bitmay.Dispose();
oImg.Dispose();
//删除源图
try
{
File.Delete(SourceFile);
}
catch { }
}
/**/
/// <summary>
/// 保存JPG时用
/// </summary>
/// <param name="mimeType"></param>
/// <returns>得到指定mimeType的ImageCodecInfo</returns>
private static ImageCodecInfo GetCodecInfo(string mimeType)
{
ImageCodecInfo[] CodecInfo = ImageCodecInfo.GetImageEncoders();
foreach (ImageCodecInfo ici in CodecInfo)
{
if (ici.MimeType == mimeType) return ici;
}
return null;
}
/**/
/// <summary>
/// 保存为JPEG格式,支持压缩质量选项
/// </summary>
/// <param name="bmp"></param>
/// <param name="FileName"></param>
/// <param name="Qty"></param>
/// <returns></returns>
public static bool KiSaveAsJPEG(Bitmap bmp, string FileName, int Qty)
{
try
{
EncoderParameter p;
EncoderParameters ps;
ps = new EncoderParameters(1);
p = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, Qty);
ps.Param[0] = p;
bmp.Save(FileName, GetCodecInfo("image/jpeg"), ps);
return true;
}
catch
{
return false;
}
}
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Drawing.Imaging;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUpLoad_Click(object sender, EventArgs e)
{
Random n = new Random();
string str="~/" +n.Next(100000).ToString()+ FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.IndexOf("."));
FileUpload1.SaveAs(Server.MapPath(str));
myGetThumbnailImage(Server.MapPath(str), @"D:\Project\ImageEdit\84283-1.jpg", 120,120, "white");
}
/// <summary>
/// 判断图片大小 Quality(upload)
/// </summary>
/// <param name="upLoad">控件</param>
/// <returns></returns>
public Boolean Quality(FileUpload upLoad)
{
if (upLoad.PostedFile.ContentLength > 50000)
{
return false;
}
else
{
return true;
}
}
public Boolean Size(string path)
{
System.Drawing.Image myThumbnail = System.Drawing.Image.FromFile(path);
if ((myThumbnail.Width > 550) && (myThumbnail.Height > 412.5))
{
System.Drawing.Image copyImage = myThumbnail.GetThumbnailImage(550, 412, null, IntPtr.Zero);
return false;
}
else
{
return true;
}
}
/// </summary>
/// <param name="SourceFile">文件在服务器上的物理地址</param>
/// <param name="strSavePathFile">保存在服务器上的路径</param>
/// <param name="ThumbWidth">宽度</param>
/// <param name="ThumbHeight">高度</param>
/// <param name="BgColor">背景</param>
public static void myGetThumbnailImage(string SourceFile, string strSavePathFile, int ThumbWidth, int ThumbHeight, string BgColor)
{
System.Drawing.Image oImg = System.Drawing.Image.FromFile(SourceFile);
//小图
int intwidth, intheight;
if (oImg.Width > oImg.Height)
{
if (oImg.Width > ThumbWidth)
{
intwidth = ThumbWidth;
intheight = (oImg.Height * ThumbWidth) / oImg.Width;
}
else
{
intwidth = oImg.Width;
intheight = oImg.Height;
}
}
else
{
if (oImg.Height > ThumbHeight)
{
intwidth = (oImg.Width * ThumbHeight) / oImg.Height; intheight = ThumbHeight;
}
else
{
intwidth = oImg.Width; intheight = oImg.Height;
}
}
//构造一个指定宽高的Bitmap
Bitmap bitmay = new Bitmap(intwidth, intheight);
Graphics g = Graphics.FromImage(bitmay);
Color myColor;
if (BgColor == null) myColor = Color.FromName("white");
else
myColor = Color.FromName(BgColor);
//用指定的颜色填充Bitmap
g.Clear(myColor);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
//开始画图
g.DrawImage(oImg, new Rectangle(0, 0, intwidth, intheight), new Rectangle(0, 0, oImg.Width, oImg.Height), GraphicsUnit.Pixel);
//bitmay.Save(strSavePathFile, System.Drawing.Imaging.ImageFormat.Jpeg);
KiSaveAsJPEG(bitmay, @"D:\Project\ImageEdit\1.jpg", 50);
g.Dispose();
bitmay.Dispose();
oImg.Dispose();
//删除源图
try
{
File.Delete(SourceFile);
}
catch { }
}
/**/
/// <summary>
/// 保存JPG时用
/// </summary>
/// <param name="mimeType"></param>
/// <returns>得到指定mimeType的ImageCodecInfo</returns>
private static ImageCodecInfo GetCodecInfo(string mimeType)
{
ImageCodecInfo[] CodecInfo = ImageCodecInfo.GetImageEncoders();
foreach (ImageCodecInfo ici in CodecInfo)
{
if (ici.MimeType == mimeType) return ici;
}
return null;
}
/**/
/// <summary>
/// 保存为JPEG格式,支持压缩质量选项
/// </summary>
/// <param name="bmp"></param>
/// <param name="FileName"></param>
/// <param name="Qty"></param>
/// <returns></returns>
public static bool KiSaveAsJPEG(Bitmap bmp, string FileName, int Qty)
{
try
{
EncoderParameter p;
EncoderParameters ps;
ps = new EncoderParameters(1);
p = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, Qty);
ps.Param[0] = p;
bmp.Save(FileName, GetCodecInfo("image/jpeg"), ps);
return true;
}
catch
{
return false;
}
}
}
稿件编号:1811475号
- 三羊开泰
- 等 级:猪一戒
- 信用值:


- 能力值:



稿件编号:1812712号
- yanxuedong
- 等 级:猪一戒
- 信用值:

- 能力值:



稿件编号:1813769号
- jiangpingchang
- 等 级:猪一戒
- 信用值:



- 能力值:



稿件编号:1820325号
- xuyuanbaihe
- 等 级:猪一戒
- 信用值:

- 能力值:



下载附件


