program案例 程序案例 project案例 code案例
当前位置:以往案例 > >program案例 程序案例 project案例 code案例
2020-08-23


program案例 This project adopts the object-oriented principle, slightly changed the Image class, and implemented a Manipulator class.

program案例
1.Description
This project adopts the object-oriented principle, slightly changed the Image class, and implemented a Manipulator class. The main functions are encapsulated in the class.

The image read in the constructor is saved in the member variable “img_”, and all subsequent operations on this image generate a copy of this member variable and write it to a new file. When the program operates the picture, it does not affect other operations.

Class diagram is as follows.


2.Pseudocode
2.1 Show R/G/B channels


Image channel_filter(Image img, Channel channel):

tmp_img = img

for i from 0 to (tmp_img.w * tmp_ing.h):

if channel == Red:

tmp_img[i] *= kRed

else if channel == Green:

tmp_img[i] *= kGreen

else if channel == Blue:

tmp_img[i] *= kBlue

return tmp_img
2.2 Change brightness
Image img_lighter(Image img, float light_rate):

tmp_img = img

for i from 0 to (tmp_img.w * tmp_ing.h):

Rgb rate = Rgb(1 + light_rate, 1 + light_rate, 1 + light_rate)

tmp_img[i] *= rate

if (tmp_img[i].r > 1)

tmp_img[i].r = 1;

if (tmp_img[i].g > 1)

tmp_img[i].g = 1;

if (tmp_img[i].b > 1)

tmp_img[i].b = 1;

if (tmp_img[i].r < 0) tmp_img[i].r = 0; if (tmp_img[i].g < 0) tmp_img[i].g = 0; if (tmp_img[i].b < 0) tmp_img[i].b = 0; return tmp_img
3.Results
3.1 Select file
aa
3.2 Show red channel
bb11
3.3 Show green channel
cc22
3.4 Show blue channel
dd33
3.5 Brightness increases by 0.2
program案例program案例44
3.6 Brightness decreases by 0.3

4.Analysis
This program basically implements the requirements mentioned in the documentation, but there are a few points that can be optimized. First, you can reimplement the Image class. Using C-style dynamic arrays as members of a class has drawbacks, especially when copying objects. Re-implementing it to the style of the stl template library avoids this inconvenience. In addition, the member variable property in the Image class is public, which does not conform to the encapsulation of the class. It is best to change its property to private and implement the get and set methods.








a

b1

c2

d3

program代写4




在线提交订单