posts - 26,  comments - 43,  trackbacks - 1
if(System.IO.File.Exists(path))
    {
     goodsid+=dt.Rows[i]["goodsid"].ToString()+",";
//     if(!System.IO.File.Exists(Picpath))
//     {
      System.Drawing.Image img=System.Drawing.Image.FromFile(path);
      //生成中图
     int w=img.Width;  //当前图片的宽
     int h=img.Height;  //当前图片的高
     int x=0;           //设置生成图片的宽
     int y=0;           //设置生成图片的高
    int curx=182;
    int cury=122;
     if(w>=curx && h<=cury)
     {
      x=curx ;
      y=curx *h/w;
     } 
     else if(h>=cury&& w<=curx )
     {
      y=cury;
      x=cury*w/h;
     }
     else if(h>=cury&& w>=curx )
     {
      if(h/cury>w/curx )
      {
       x=curx ;
       y=curx *h/w;
      }
      else
      {
       y=cury;
       x=cury*w/h;
      }
     }
     else if(h<=cury&& w<=curx )
     {
      x=img.Width;
      y=img.Height;
     }
      System.Drawing.Image  newimg=img.GetThumbnailImage(x,y,null,new System.IntPtr(0));
      newimg.Save(Picpath,System.Drawing.Imaging.ImageFormat.Jpeg);
      img.Dispose();
      newimg.Dispose();

上面写的这个有些错误。。。
if(System.IO.File.Exists(path))
    {
     goodsid+=dt.Rows[i]["goodsid"].ToString()+",";
//     if(!System.IO.File.Exists(Picpath))
//     {
      System.Drawing.Image img=System.Drawing.Image.FromFile(path);
      //生成中图
     int w=img.Width;  //当前图片的宽
     int h=img.Height;  //当前图片的高
     int x=0;           //设置生成图片的宽
     int y=0;           //设置生成图片的高
    int curx=182;
    int cury=122;
     if(w>=curx && h<=cury)
     {
      x=curx ;
      y=curx *h/w;
     } 
     else if(h>=cury&& w<=curx )
     {
      y=cury;
      x=cury*w/h;
     }
     else if(h>=cury&& w>=curx )
     {
      if(h/cury<w/curx )
      {
       x=curx ;
       y=curx *h/w;
      }
      else
      {
       y=cury;
       x=cury*w/h;
      }
     }
     else if(h<=cury&& w<=curx )
     {
      x=img.Width;
      y=img.Height;
     }
      System.Drawing.Image  newimg=img.GetThumbnailImage(x,y,null,new System.IntPtr(0));
      newimg.Save(Picpath,System.Drawing.Imaging.ImageFormat.Jpeg);
      img.Dispose();
      newimg.Dispose();

这个修正后的
posted on 2006-11-07 15:09 oo縼箻ㄗs.鋒 阅读(4601) 评论(2)  编辑 收藏 网摘

FeedBack:
2007-03-23 19:36 | 545[未注册用户]
if(System.IO.File.Exists(path))
{
goodsid+=dt.Rows[i]["goodsid"].ToString()+",";
// if(!System.IO.File.Exists(Picpath))
// {
System.Drawing.Image img=System.Drawing.Image.FromFile(path);
//生成中图
int w=img.Width; //当前图片的宽
int h=img.Height; //当前图片的高
int x=0; //设置生成图片的宽
int y=0; //设置生成图片的高
int curx=182;
int cury=122;
if(w>=curx && h<=cury)
{
x=curx ;
y=curx *h/w;
}
else if(h>=cury&& w<=curx )
{
y=cury;
x=cury*w/h;
}
else if(h>=cury&& w>=curx )
{
if(h/cury<w/curx )
{
x=curx ;
y=curx *h/w;
}
else
{
y=cury;
x=cury*w/h;
}
}
else if(h<=cury&& w<=curx )
{
x=img.Width;
y=img.Height;
}
System.Drawing.Image newimg=img.GetThumbnailImage(x,y,null,new System.IntPtr(0));
newimg.Save(Picpath,System.Drawing.Imaging.ImageFormat.Jpeg);
img.Dispose();
newimg.Dispose();

  回复  引用    
2007-07-24 16:42 | aiweb[未注册用户]
哦,谢谢分享。
  回复  引用    



发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 552963




相关文章:

相关链接:

<2006年11月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

与我联系

搜索

 

常用链接

留言簿

我参加的小组

我参与的团队

我的标签

随笔分类

随笔档案

博客站

一些圈子

阅读排行榜

评论排行榜