随笔 - 6  文章 - 8 评论 - 13 
<2007年5月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(2)

随笔分类(4)

文章档案(8)

Symbian Resources

VC Resources

搜索

  •  

最新评论

阅读排行榜

评论排行榜

注:  前阵时在做一个在线图片处理的ActiveX控件,用到了黎叔的的开源项目"ImageStone",很不错,在这里还要感谢黎叔.
帮我实现了大部份功能 ,由于客户需要裁切功能,黎叔在代码中并没有去实现.我又去Google一下也没找到合适的(我的拿来主义还是很重的,MSDN上也没找到关于GDI+关于图片裁切处理的VC版本..NET的到是找了一个).无耐,自已实现吧,现在把部份代码贴出来共享一下.

 1inline void FCObjImage::Cropping(RECT reCropping) 
 2    if (!IsValidImage() || (reCropping.right <= 0|| (reCropping.bottom <= 0)) 
 3         return;
 4    if((int)reCropping.right==Width()&&(int)reCropping.bottom==Height())
 5         return;
 6    int nNewWidth = (int)(reCropping.right - reCropping.left);
 7    int nNewHeight = (int)(reCropping.bottom - reCropping.top); 
 8
 9    // first backup image const FCObjImage imgOld(*this) ;
10    if (!Create (nNewWidth, nNewHeight, imgOld.ColorBits())) {
11        assert(false) ; 
12        return ; 
13     }
 
14     
15     // duplicate palette
16     if (ColorBits() <= 8
17         CopyPalette (imgOld) ;
18     
19    const int nSpan = ColorBits() / 8 ;
20
21    for (int y=reCropping.top ; y < reCropping.bottom ; y++{
22          BYTE * pPixel = GetBits (y-reCropping.top) ;
23          for (int x=reCropping.left ; x < reCropping.right ; x++
24                 BYTE * pOld = imgOld.GetBits(x,y); 
25                 FCColor::CopyPixel (pPixel, pOld, nSpan) ;
26                 pPixel += nSpan ; 
27         }

28      }
 
29}

30
posted on 2007-05-07 17:49 Boon 阅读(1344) 评论(3)  编辑 收藏 引用 所属分类: VC Other

FeedBack:
# re: 完善ImageStone中的图片裁切 2007-05-12 10:31 piccer
也可以这样
FCObjImage t ;
img.GetSubBlock(&t, rc) ;
img = t ;
这样可以省却备份原图,只复制小缩略图  回复  更多评论
  
# re: 完善ImageStone中的图片裁切 2007-08-14 12:14 Boon
这个是缩略图,好像ImageStone中没有提供裁切..  回复  更多评论
  
# re: 完善ImageStone中的图片裁切 2008-02-28 07:42 abc不重名
@Boon
哪个讲得这个是缩略图啊,你没有看源代码?  回复  更多评论
  
只有注册用户登录后才能发表评论。