1# graphics_effect 2 3## Description 4graphics_effect is an important component of OpenHarmony's graphics subsystem, providing the necessary visual effects algorithm capabilities for the graphics subsystem, including blur, shadow, gradient, grayscale, brighten, invert, enhance, etc. 5 6## Software Architecture 7 8 9The layered description of Graphics Effect is as follows: 10 11• Interface layer: Graphics Effect opens its capabilities to the outside world through ArkUI, UIEffect, and EffectKit. 12 13• Implementation layer: divided into three modules: GERender, GEVisualEffect, and GEVisualEffectContainer. 14| Modules | Capability description | 15|--------------------------------------------------|-----------------------------------------------------------------------------------------------| 16| GERender(rendering) | provides drawing capabilities and draws the effects of GEVisualEffect onto the target canvas. | 17| GEVisualEffect(visual effect) | implementation of specific visual effect capabilities. | 18| GEVisualEffectContainer(visual effect container) | convenient integration of multiple visual effects. | 19 20## Directory structure 21``` 22foundation/graphic/graphics_effect/ 23├── figures # Image directory referenced by Markdown 24├── include # Graphics Effect interface storage directory 25│ ├── ext # Dynamic loading framework interface and algorithm interface storage directory 26├── src # Source code storage directory 27│ ├── ext # Dynamic loading framework and algorithm interface implementation storage directory 28└── test # Test case storage directory 29 ├── fuzztest # Fuzz test case storage directory 30 └── unittest # Unit test case storage directory 31``` 32 33## Installation 34 35Not involved 36 37## Instructions 38 39The capabilities of this component have been integrated into system UI rendering scenarios such as the desktop, status bar, and control center, and users can directly operate and use it and experience the corresponding effects. 40 41### 1.Draw the specified visual effect onto the canvas 42 43Based on the specified image, apply the visual effect contained in the GEVisualEffectContainer and draw it directly onto the passed canvas. 44``` 45void DrawImageEffect(Drawing::Canvas& canvas, Drawing::GEVisualEffectContainer& veContainer, 46 const std::shared_ptr<Drawing::Image>& image, const Drawing::Rect& src, const Drawing::Rect& dst, 47 const Drawing::SamplingOptions& sampling); 48``` 49Example: 50``` 51 Drawing::Canvas canvas; 52 auto image = std::make_shared<Drawing::Image>(); 53 auto visualEffectContainer = std::make_shared<Drawing::GEVisualEffectContainer>(); 54 DrawImageRectAttributes attr; 55 56 auto geRender = std::make_shared<GraphicsEffectEngine::GERender>(); 57 geRender->DrawImageEffect(canvas, *visualEffectContainer, image, attr.src, attr.src, Drawing::SamplingOptions()); 58``` 59 60### 2.Draw the specified visual effect onto the canvas and return the drawing result as an image 61 62Based on the specified image, apply the visual effect contained in the GEVisualEffectContainer and return the drawing result as image 63``` 64std::shared_ptr<Drawing::Image> ApplyImageEffect(Drawing::Canvas& canvas, 65 Drawing::GEVisualEffectContainer& veContainer, const std::shared_ptr<Drawing::Image>& image, 66 const Drawing::Rect& src, const Drawing::Rect& dst, const Drawing::SamplingOptions& sampling); 67``` 68Example: 69``` 70 Drawing::Canvas canvas; 71 auto image = std::make_shared<Drawing::Image>(); 72 auto visualEffectContainer = std::make_shared<Drawing::GEVisualEffectContainer>(); 73 DrawImageRectAttributes attr; 74 75 auto geRender = std::make_shared<GraphicsEffectEngine::GERender>(); 76 auto outImage = geRender->ApplyImageEffect(canvas, *visualEffectContainer, image, attr.src, attr.src, Drawing::SamplingOptions()); 77``` 78