1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "bitmap_test.h"
17 
18 using namespace OHOS::Media;
19 
20 namespace OHOS {
21 namespace Rosen {
22 namespace Drawing {
23 static constexpr int32_t BITMAP_WIDTH = 200;
24 static constexpr int32_t BITMAP_HEIGHT = 200;
25 static constexpr scalar STROKE_WIDTH = 10;
26 static constexpr scalar POSITION_X = 500;
27 static constexpr scalar POSITION_Y = 500;
28 
29 using TestFunc = std::function<void(Canvas&, uint32_t, uint32_t)>;
TestDrawBitmap(Canvas & canvas,uint32_t width,uint32_t height)30 void BitmapTest::TestDrawBitmap(Canvas& canvas, uint32_t width, uint32_t height)
31 {
32     LOGI("+++++++ TestDrawBitmap");
33     Bitmap bmp;
34     BitmapFormat format { COLORTYPE_RGBA_8888, ALPHATYPE_OPAQUE };
35     bmp.Build(BITMAP_WIDTH, BITMAP_HEIGHT, format); // bitmap width and height
36     bmp.ClearWithColor(Drawing::Color::COLOR_BLUE);
37 
38     Pen pen;
39     pen.SetAntiAlias(true);
40     pen.SetColor(Drawing::Color::COLOR_BLUE);
41     pen.SetWidth(STROKE_WIDTH); // The thickness of the pen is 10
42     canvas.AttachPen(pen);
43     canvas.DrawBitmap(bmp, POSITION_X, POSITION_Y); // draw bitmap at (fx, fy)
44 
45     LOGI("------- TestDrawBitmap");
46 }
47 
BitmapTestCase()48 std::vector<BitmapTest::TestFunc> BitmapTest::BitmapTestCase()
49 {
50     std::vector<TestFunc> testFuncVec;
51     testFuncVec.push_back(TestDrawBitmap);
52     return testFuncVec;
53 }
54 } // namespace Drawing
55 } // namespace Rosen
56 } // namespace OHOS
57