1 /*
2 * Copyright (c) 2024 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 #include "newsurface.h"
16
17 #include <multimedia/image_framework/image_mdk_common.h>
18 #include <native_drawing/drawing_brush.h>
19 #include <native_drawing/drawing_color.h>
20 #include <native_drawing/drawing_color_filter.h>
21 #include <native_drawing/drawing_filter.h>
22 #include <native_drawing/drawing_image.h>
23 #include <native_drawing/drawing_mask_filter.h>
24 #include <native_drawing/drawing_matrix.h>
25 #include <native_drawing/drawing_path.h>
26 #include <native_drawing/drawing_pen.h>
27 #include <native_drawing/drawing_point.h>
28 #include <native_drawing/drawing_round_rect.h>
29 #include <native_drawing/drawing_sampling_options.h>
30 #include <native_drawing/drawing_shader_effect.h>
31
32 #include "test_common.h"
33
34 #include "common/log_common.h"
35
36 enum {
37 K_W = 300, // 300 是位图宽度
38 K_H = 140, // 140 是位图高度
39 };
40
NewSurfaceGM()41 NewSurfaceGM::NewSurfaceGM()
42 {
43 bitmapWidth_ = K_W;
44 bitmapHeight_ = K_H;
45 fileName_ = "surfacenew";
46 }
47
OnTestFunction(OH_Drawing_Canvas * canvas)48 void NewSurfaceGM::OnTestFunction(OH_Drawing_Canvas* canvas)
49 {
50 uint32_t w = 100; // 100定义了要创建的位图bm的宽度
51 uint32_t h = 100; // 100定义了要创建的位图bm的高度
52 OH_Drawing_Bitmap* bm = OH_Drawing_BitmapCreate();
53 OH_Drawing_BitmapFormat format = { OH_Drawing_ColorFormat::COLOR_FORMAT_RGBA_8888,
54 OH_Drawing_AlphaFormat::ALPHA_FORMAT_PREMUL };
55 OH_Drawing_BitmapBuild(bm, w, h, &format);
56
57 // 将画布与bitmap绑定,画布画的内容会输出到绑定的bitmap内存中
58 OH_Drawing_Canvas* bitmapCanvas = OH_Drawing_CanvasCreate();
59 OH_Drawing_CanvasBind(bitmapCanvas, bm);
60 // 生成效果图不一样,只是色差有点区别,色彩数据用的源码,源码照片生成色差与数据不符。
61 OH_Drawing_CanvasClear(bitmapCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00));
62
63 float left = 10; // 10 定义了绘制位图到画布上的位置
64 float top = 10; // 10 定义了绘制位图到画布上的位置
65 // 其中surf->makeSurface以及canvas->drawImage在OH接口中并未实现,故用OH_Drawing_CanvasDrawBitmap接口去把图绘制出来
66 OH_Drawing_CanvasDrawBitmap(canvas, bm, left, top);
67 float leftMove = 120; // 120 定义了绘制位图到画布上的位置
68 float topMove = 10; // 10 定义了绘制位图到画布上的位置
69 OH_Drawing_CanvasDrawBitmap(canvas, bm, leftMove, topMove);
70 // 释放内存
71 OH_Drawing_BitmapDestroy(bm);
72 OH_Drawing_CanvasDestroy(bitmapCanvas);
73 }