图片已经存在数据库了,数据库的字段是img,字段内容如:/uploadimg/2005222123530.jpg
存在数据库里的图片大小不一,有的是350*220,有的200*300等等。
(注:以上的代码是用asp写的)
现在的问题是,怎么把他们按等比例的缩小呢?
参考网址是:http://www.zjhuaxia.com/page/pro.asp
就是把上面的产品图片自动按等比例缩小。
用客户端的代码不稳定,请问有什么好的方法呢?
存在数据库里的图片大小不一,有的是350*220,有的200*300等等。
(注:以上的代码是用asp写的)
现在的问题是,怎么把他们按等比例的缩小呢?
参考网址是:http://www.zjhuaxia.com/page/pro.asp
就是把上面的产品图片自动按等比例缩小。
用客户端的代码不稳定,请问有什么好的方法呢?
解决方案 »
- 向Access 数据库中插入数据,执行成功,但没有数据
- 我靠,,access太蛋疼了,,搞了半天insert into错误
- 急!!!!求大神帮忙把一个字符串按要求转换成数组(这是我所有的分了)
- Silverlight学习数据和RIA服务时,找不到domain service class模板!
- 急求单点登录页面程序
- 如果在asp.net中回发html字符串?
- javascript中移除事件
- 求一.NET下可用的风格良好的的个人网站的模板 分不够可以再加 UP也有分
- 水晶报表问题|!
- 有谁接触过freetextbox,有问题请教.
- 求Datalist控件分页的代码,满足要求给100分
- 急!!!关于从数据表取出数据在控件中显示的问题
1。把图片文件(JPG GIF PNG)上传,
2。保存到指定的路径(在web.config中设置路径,以文件的原有格式保存),
3。并自动生成指定宽度的(在web.config中设置宽度)
4。和指定格式的(在web.config中指定缩略图的格式)
5。和原图比例相同的缩略图(根据宽度和原图的宽和高计算所略图的高度)
6。可以判断是否已经存在文件
7。如果不覆盖,则给出错误
8。如果选中"覆盖原图"checkbox,则覆盖原图。
9。可以根据要求,在webform上设置1个以上的file input和相应的checkbox
10。并在文件上传完毕后,显示原图的文件名,尺寸,字节,和
11。缩略图的文件名尺寸。
12。缩略图的文件名格式:原图+"_thumb."+指定格式,如:test.jpg_thumb.gif,以便于管理。 --------------------
public void UploadFile(object sender, System.EventArgs e)
{
string imgNameOnly, imgNameNoExt, imgExt;
string imgThumbnail;
int erroNumber = 0;
System.Drawing.Image oriImg, newImg;
string strFePicSavePath = ConfigurationSettings.AppSettings["FePicSavePath"].ToString();
string strFePicThumbFormat = ConfigurationSettings.AppSettings["FePicThumbFormat"].ToString().ToLower();
int intFeThumbWidth = Int32.Parse(ConfigurationSettings.AppSettings["FePicThumbWidth"]);
string fileExt; StringBuilder picInfo = new StringBuilder();
if(Page.IsValid)
{
for(int i = 0;i < Request.Files.Count; i++)
{
HttpPostedFile PostedFile = Request.Files[i];
fileExt = (System.IO.Path.GetExtension(PostedFile.FileName)).ToString().ToLower();
imgNameOnly = System.IO.Path.GetFileName(PostedFile.FileName);
if(fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".png")
{ if(System.IO.File.Exists(strFePicSavePath + imgNameOnly) && (checkboxlistRewrite.Items[i].Selected == false))
{
erroNumber = erroNumber + 1;
picInfo.Append("<b>错误:</b>文件("+ (i+1) +") " + imgNameOnly + " 已经存在,请修改文件名<br>" );
}
}
else
{
erroNumber = erroNumber + 1;
picInfo.Append("<b>错误:</b>文件("+ (i+1) +") " + imgNameOnly + " 扩展名 " + fileExt + " 不被许可<br>" );
} } if(erroNumber > 0)
{
picInfo.Append("<font color=red>全部操作均未完成,请修改错误,再进行操作</font><br>");
}
else
{
for(int i = 0;i < Request.Files.Count; i++)
{
HttpPostedFile PostedFile = Request.Files[i];
imgNameOnly = System.IO.Path.GetFileName(PostedFile.FileName);
imgNameNoExt = System.IO.Path.GetFileNameWithoutExtension(PostedFile.FileName);
imgExt = System.IO.Path.GetExtension(PostedFile.FileName).ToString().ToLower();
oriImg = System.Drawing.Image.FromStream(PostedFile.InputStream);
newImg = oriImg.GetThumbnailImage(intFeThumbWidth, intFeThumbWidth * oriImg.Height/oriImg.Width,null,new System.IntPtr(0));
switch(imgExt)
{
//case ".jpeg":
case ".jpg":
oriImg.Save(strFePicSavePath + imgNameOnly , System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case ".gif":
oriImg.Save(strFePicSavePath + imgNameOnly , System.Drawing.Imaging.ImageFormat.Gif);
break;
case ".png":
oriImg.Save(strFePicSavePath + imgNameOnly , System.Drawing.Imaging.ImageFormat.Png);
break;
}
//oriImg.Save(ConfigurationSettings.AppSettings["FePicSavePath"] + imgNameNoExt + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
switch(strFePicThumbFormat)
{
//jpeg format can get the smallest file size, and the png is the largest size
//case "jpeg":
case "jpg":
newImg.Save(strFePicSavePath + imgNameOnly + "_thumb.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
imgThumbnail = imgNameOnly + "_thumb.jpg";
break;
case "gif":
newImg.Save(strFePicSavePath + imgNameOnly + "_thumb.gif",System.Drawing.Imaging.ImageFormat.Gif);
imgThumbnail = imgNameOnly + "_thumb.gif";
break;
case "png":
newImg.Save(strFePicSavePath + imgNameOnly + "_thumb.png",System.Drawing.Imaging.ImageFormat.Png);
imgThumbnail = imgNameOnly + "_thumb.png";
break;
default:
newImg.Save(strFePicSavePath + imgNameOnly + "_thumb.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
imgThumbnail = imgNameOnly + "_thumb.jpg";
break;
}//switch
picInfo.Append("<b>文件 名:</b>" + imgNameOnly + " ( " + oriImg.Width + " x " + oriImg.Height + " ) " + PostedFile.ContentLength/1024 + "KB<br>");
picInfo.Append("<b>缩略图名:</b>" + imgThumbnail + " ( " + newImg.Width + " x " + newImg.Height + " )<br><br>");
oriImg.Dispose();
newImg.Dispose();
}//for
picInfo.Append("<font color=red>所有操作成功</font><br>"); }// if erronumber = 0
}
else
{
picInfo.Append("<font color=red>有错误,请检查。操作未成功</font><br>"); } lblPicInfo.Text = picInfo.ToString();
<img src=....jpg whith=200>
对于图像,你只固定了它的宽度,不固定它的高度,它自然就等比例缩小了
这样的话,整个页面的框架都会变得上小不一了,非常难看。
to:sky_rui(枫语)
那好象是第三方组件,要在服务器上注册的,有点麻烦。最好用asp.net的代码,服务器支持。