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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30
