注: 前阵时在做一个在线图片处理的ActiveX控件,用到了黎叔的的开源项目"ImageStone",很不错,在这里还要感谢黎叔.
帮我实现了大部份功能
,由于客户需要裁切功能,黎叔在代码中并没有去实现.我又去Google一下也没找到合适的(我的拿来主义还是很重的,MSDN上也没找到关于GDI+关于图片裁切处理的VC版本..NET的到是找了一个).无耐,自已实现吧,现在把部份代码贴出来共享一下.
1
inline 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 阅读(1364)
评论(3) 编辑 收藏 引用 所属分类:
VC Other