就是用户在上传一张图片,比如一张400*300大小的图片test.gif,服务器在接收完后同时创建另外一张test.gif的40*30的缩小图view.gif。应该可以实现吧,现求代码~~80分马上奉献上(心痛啊,自己太懒了-_-)
解决方案 »
- xhtml 1.0标准开发的WEB应用,客户端用ie6访问会出现不兼容现象吗
- 关于动态创建select select个数不确定
- 一直做的是c#的c/s模式的开发,想学asp.net,请高手给点意见或者建议
- vs 中Insert数据数据库中数据不变化
- 求sql语句,谢先
- 100分,求using(SqlConnection newconn = new SqlConnection()){……}中用不用newconn.close()方法??
- 关于保存上传路径的问题
- 能不能在datagrid的单元格里插入label控件?
- 该怎么进一步学习c#语言?(请各位高手谈一下学习经验,我想去应聘.net该怎么做)
- 求sohu首页上两边flash广告放置的源代码!!
- [弟兄们急]关于日历的问题
- (初学者)datgrid加checkbox.我用js来判断checkboxs是否选中,怎么传参?
//生成缩略图函数
public static void MakeSmallImg(System.Web.HttpPostedFile postFile,string saveImg,System.Double Width,System.Double Height)
{
//原始图片名称
string originalFilename = postFile.FileName;
//生成的高质量图片名称
string strGoodFile = saveImg; //从文件取得图片对象
System.Drawing.Image image = System.Drawing.Image.FromStream(postFile.InputStream,true); System.Double NewWidth,NewHeight;
if(image.Width>image.Height)
{
NewWidth=Width;
NewHeight=image.Height*(NewWidth/image.Width);
}
else
{
NewHeight=Height;
NewWidth=(NewHeight/image.Height)*image.Width;
} if (NewWidth>Width)
{
NewWidth=Width;
}
if (NewHeight>Height)
{
NewHeight=Height;
} //取得图片大小
System.Drawing.Size size = new Size((int)NewWidth,(int)NewHeight);
//新建一个bmp图片
System.Drawing.Image bitmap = new System.Drawing.Bitmap(size.Width,size.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(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); ///文字水印
//System.Drawing.Graphics G=System.Drawing.Graphics.FromImage(bitmap);
//System.Drawing.Font f=new Font("宋体",10);
//System.Drawing.Brush b=new SolidBrush(Color.Black);
//G.DrawString("myohmine",f,b,10,10);
//G.Dispose(); ///图片水印
//System.Drawing.Image copyImage = System.Drawing.Image.FromFile(System.Web.HttpContext.Current.Server.MapPath("pic/1.gif"));
//Graphics a = Graphics.FromImage(bitmap);
//a.DrawImage(copyImage, new Rectangle(bitmap.Width-copyImage.Width,bitmap.Height-copyImage.Height,copyImage.Width, copyImage.Height),0,0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel); //copyImage.Dispose();
//a.Dispose();
//copyImage.Dispose(); //保存高清晰度的缩略图
bitmap.Save(strGoodFile, System.Drawing.Imaging.ImageFormat.Jpeg); g.Dispose();
image.Dispose();
bitmap.Dispose();
}
#endregion
switch(this.selectfile.PostedFile.ContentType.ToString())
{
case "image/pjpeg":
string filename = Hmg.DBAccess.Tools.GetGuidString();
string filename_small = filename+"_";
filename += ".JPG";
filename_small += ".JPG";
this.selectfile.PostedFile.SaveAs(HttpRuntime.AppDomainAppPath+@"UploadFile\UserMaterial\1\"+filename);//*
System.Drawing.Image myImage = System.Drawing.Image.FromFile(HttpRuntime.AppDomainAppPath+@"UploadFile\UserMaterial\1\"+filename);//*
string su = System.Configuration.ConfigurationSettings.AppSettings["WebUrl"]+"uploadfile/usermaterial/1/"+filename;//*;
//横图
if(myImage.Width > myImage.Height || myImage.Width == myImage.Height)
{
if(myImage.Width > 124)
{
su = System.Configuration.ConfigurationSettings.AppSettings["WebUrl"]+"uploadfile/usermaterial/1/"+filename_small;//*
double percent = Math.Round(124 / (double)myImage.Width , 2);//缩放百分比
int new_width = 124;
int new_height = Convert.ToInt32(Math.Round(myImage.Height * percent));
Hmg.DBAccess.Tools.MakeSmallImg(this.selectfile.PostedFile,HttpRuntime.AppDomainAppPath+@"UploadFile\UserMaterial\1\"+filename_small,new_width,new_height);//*
}
}
//竖图
if(myImage.Height > myImage.Width)
{
if(myImage.Height > 124)
{
su = System.Configuration.ConfigurationSettings.AppSettings["WebUrl"]+"uploadfile/usermaterial/1/"+filename_small;//*
double percent = Math.Round(124 / (double)myImage.Height , 2);//缩放百分比
int new_width = Convert.ToInt32(Math.Round(myImage.Height * percent));
int new_height = 124;
Hmg.DBAccess.Tools.MakeSmallImg(this.selectfile.PostedFile,HttpRuntime.AppDomainAppPath+@"UploadFile\UserMaterial\1\"+filename_small,new_width,new_height);//*
}
}
//写数据库
UserMaterialInfo myU = new Hmg.Model.UserMaterialInfo();
myU.ImageSmallUrl = su;
myU.UserNumber = Convert.ToInt32(Session["UserNumber"]);
myU.Name = Hmg.DBAccess.Tools.CleanInputText(this.txtName.Text,255);
myU.Url = System.Configuration.ConfigurationSettings.AppSettings["WebUrl"]+"uploadfile/usermaterial/1/"+filename;//*
myU.Size = this.selectfile.PostedFile.ContentLength;
myU.ImageWidth = myImage.Width;
myU.ImageHeight = myImage.Height;
myU.FileTypes = 1;
myU.Types = 1;//1封面 2封二 3内页 4封底 5其它图片 6背景音乐 //*
myImage.Dispose();
if(myMat.AddUserMaterial(myU))
{
Response.Write(Hmg.DBAccess.Tools.Alert("记录添加成功!"));
//绑定
this.binddlst(Convert.ToInt32(ViewState["pagenow"]));
}
break;
......
MSN:[email protected]