1 /*
2 * Copyright (c) 2020-2021 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 "ui_test_image.h"
17 #include "common/screen.h"
18 #include "components/ui_label.h"
19 #include "default_resource/check_box_res.h"
20 #if (ENABLE_GIF == 1)
21 #include "components/ui_image_view.h"
22 #include "test_resource_config.h"
23 #endif
24 #include "imgdecode/image_load.h"
25
26 namespace OHOS {
27 namespace {
28 int16_t g_height = 0;
29 }
30
SetUp()31 void UITestImage::SetUp()
32 {
33 g_height = 0;
34 if (container_ == nullptr) {
35 container_ = new UIScrollView();
36 container_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
37 container_->SetHorizontalScrollState(false);
38 }
39 }
40
TearDown()41 void UITestImage::TearDown()
42 {
43 DeleteChildren(container_);
44 container_ = nullptr;
45 #if (ENABLE_GIF == 1)
46 gifImageView_ = nullptr;
47 gifToGif_ = nullptr;
48 gifToJpeg_ = nullptr;
49 gifToPng_ = nullptr;
50 gifToBin01_ = nullptr;
51 gifToBin02_ = nullptr;
52 gifToBin03_ = nullptr;
53 gifToBin04_ = nullptr;
54 #endif
55 }
56
GetTestView()57 const UIView* UITestImage::GetTestView()
58 {
59 UIKit_UIImage_Test_SetImage_001();
60 UIKit_UIImage_Test_SetImage_002();
61 UIKit_UIImage_Test_SetImage_004();
62 UIKit_UIImage_Test_SetImage_005();
63 UIKit_UIImage_Test_SetImage_006();
64 UIKit_UIImage_Test_SetImage_007();
65 UIKit_UIImage_Test_SetImage_008();
66 UIKit_UIImage_Test_SetImage_009();
67 UIKit_UIImage_Test_SetImage_010();
68 UIKit_UIImage_Test_SetImage_011();
69 UIKit_UIImage_Test_SetImage_012();
70 UIKit_UIImage_Test_SetImage_013();
71 UIKit_UIImage_Test_SetImage_014();
72 #if (ENABLE_GIF == 1)
73 UIKit_UIImage_Test_SetImage_015();
74 UIKit_UIImage_Test_SetImage_016();
75 #endif
76 UIKit_UIImage_Test_Uncompress_001();
77 UIKit_UIImage_Test_Resize_001();
78 return container_;
79 }
80
GetCharByImageSrcType(ImageSrcType srcType) const81 const char* UITestImage::GetCharByImageSrcType(ImageSrcType srcType) const
82 {
83 if (srcType == IMG_SRC_VARIABLE) {
84 return "the src of image is variable type";
85 } else if (srcType == IMG_SRC_FILE) {
86 return "the src of image is file type";
87 } else {
88 return "Null";
89 }
90 }
91
UIKit_UIImage_Test_SetImage_001()92 void UITestImage::UIKit_UIImage_Test_SetImage_001()
93 {
94 if (container_ != nullptr) {
95 UILabel* label = new UILabel();
96 container_->Add(label);
97 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height + 5, // 5: increase y-coordinate
98 Screen::GetInstance().GetWidth(), TITLE_LABEL_DEFAULT_HEIGHT);
99 label->SetText("rgb888 格式图片测试 ");
100 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
101
102 UIImageView* imageView = new UIImageView();
103 imageView->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 40); // 40 : offset
104 imageView->SetWidth(50); // 50 : size
105 imageView->SetHeight(50); // 50 : size
106 imageView->SetSrc(BLUE_RGB888_IMAGE_PATH);
107
108 UILabel* label2 = new UILabel();
109 // 160 : offset 65 : offset 300 : offset
110 label2->SetPosition(160, g_height + 65, 300, TITLE_LABEL_DEFAULT_HEIGHT);
111 label2->SetText(GetCharByImageSrcType(imageView->GetSrcType()));
112 label2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
113 label2->SetStyle(STYLE_TEXT_COLOR, Color::Black().full);
114 label2->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full);
115 label2->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
116
117 container_->Add(label2);
118 container_->Add(imageView);
119 g_height += 130; // offset=130
120 }
121 }
122
UIKit_UIImage_Test_SetImage_002()123 void UITestImage::UIKit_UIImage_Test_SetImage_002()
124 {
125 if (container_ != nullptr) {
126 UILabel* label = new UILabel();
127 container_->Add(label);
128 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, Screen::GetInstance().GetWidth(),
129 TITLE_LABEL_DEFAULT_HEIGHT);
130 label->SetText("显示ARGB8888bin文件图片 ");
131 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
132
133 UIImageView* imageView = new UIImageView();
134 imageView->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 30); // 30: increase offset
135 imageView->SetWidth(50); // 50 : size
136 imageView->SetHeight(50); // 50 : size
137 imageView->SetSrc(BLUE_ARGB8888_IMAGE_PATH);
138
139 container_->Add(imageView);
140 g_height += 120; // offset=120
141 }
142 }
143
UIKit_UIImage_Test_SetImage_004()144 void UITestImage::UIKit_UIImage_Test_SetImage_004()
145 {
146 if (container_ != nullptr) {
147 UILabel* label = new UILabel();
148 container_->Add(label);
149 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height + 5, // 5: increase offset
150 Screen::GetInstance().GetWidth(), TITLE_LABEL_DEFAULT_HEIGHT); // 5: increase offset
151 label->SetText("显示RGB565bin文件图片 ");
152 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
153
154 UIImageView* imageView = new UIImageView();
155 imageView->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 35); // 35 : offset
156 imageView->SetWidth(50); // 50 : size
157 imageView->SetHeight(50); // 50 : size
158 imageView->SetSrc(BLUE_RGB565_IMAGE_PATH);
159 imageView->GetHeight();
160
161 container_->Add(imageView);
162 g_height += 140; // offset=140
163 }
164 }
165
UIKit_UIImage_Test_SetImage_005()166 void UITestImage::UIKit_UIImage_Test_SetImage_005()
167 {
168 if (container_ != nullptr) {
169 UILabel* label = new UILabel();
170 container_->Add(label);
171 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, Screen::GetInstance().GetWidth(),
172 TITLE_LABEL_DEFAULT_HEIGHT);
173 label->SetText("显示ARGB8888 数组型图片 ");
174 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
175
176 UIImageView* imageView = new UIImageView();
177 imageView->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 40); // 40 : increase offset
178 imageView->SetWidth(50); // 50 : size
179 imageView->SetHeight(50); // 50 : size
180 imageView->SetSrc(GetCheckBoxOnInfo());
181 imageView->GetHeight();
182
183 UIImageView* imageView2 = new UIImageView();
184 imageView2->SetPosition(110, g_height + 40); // 110 : offset 40 : increase offset
185 imageView2->SetWidth(50); // 50 : size
186 imageView2->SetHeight(50); // 50 : size
187 imageView2->SetSrc(GetCheckBoxOffInfo());
188 imageView2->GetHeight();
189
190 container_->Add(imageView);
191 container_->Add(imageView2);
192 g_height += 100; // offset=100
193 }
194 }
195
UIKit_UIImage_Test_SetImage_006()196 void UITestImage::UIKit_UIImage_Test_SetImage_006()
197 {
198 if (container_ != nullptr) {
199 UILabel* label = new UILabel();
200 container_->Add(label);
201 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, Screen::GetInstance().GetWidth(),
202 TITLE_LABEL_DEFAULT_HEIGHT);
203 label->SetText("显示24位真彩色jpg图片 ");
204 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
205
206 UIImageView* imageView = new UIImageView();
207 imageView->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 30); // 30 : offset
208 imageView->SetWidth(50); // 50 : size
209 imageView->SetHeight(50); // 50 : size
210 imageView->SetSrc(JPEG_IMAGE_PATH);
211 imageView->GetHeight();
212 container_->Add(imageView);
213 g_height += 190; // offset=190
214 }
215 }
216
UIKit_UIImage_Test_SetImage_007()217 void UITestImage::UIKit_UIImage_Test_SetImage_007()
218 {
219 if (container_ != nullptr) {
220 UILabel* label = new UILabel();
221 container_->Add(label);
222 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, Screen::GetInstance().GetWidth(),
223 TITLE_LABEL_DEFAULT_HEIGHT);
224 label->SetText("显示位深1索引png图片 ");
225 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
226
227 UIImageView* imageView = new UIImageView();
228 imageView->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 30); // 30 : offset
229 imageView->SetWidth(50); // 50 : size
230 imageView->SetHeight(50); // 50 : size
231 imageView->SetSrc(PNG_1_PALETTE_IMAGE_PATH);
232 imageView->GetHeight();
233 container_->Add(imageView);
234 g_height += 90; // offset=90
235 }
236 }
237
UIKit_UIImage_Test_SetImage_008()238 void UITestImage::UIKit_UIImage_Test_SetImage_008()
239 {
240 if (container_ != nullptr) {
241 UILabel* label = new UILabel();
242 container_->Add(label);
243 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, Screen::GetInstance().GetWidth(),
244 TITLE_LABEL_DEFAULT_HEIGHT);
245 label->SetText("显示位深2索引png图片 ");
246 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
247
248 UIImageView* imageView = new UIImageView();
249 imageView->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 30); // 30 : offset
250 imageView->SetWidth(50); // 50 : size
251 imageView->SetHeight(50); // 50 : size
252 imageView->SetSrc(PNG_2_PALETTE_IMAGE_PATH);
253 imageView->GetHeight();
254 container_->Add(imageView);
255 g_height += 90; // offset=90
256 }
257 }
258
UIKit_UIImage_Test_SetImage_009()259 void UITestImage::UIKit_UIImage_Test_SetImage_009()
260 {
261 if (container_ != nullptr) {
262 UILabel* label = new UILabel();
263 container_->Add(label);
264 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, Screen::GetInstance().GetWidth(),
265 TITLE_LABEL_DEFAULT_HEIGHT);
266 label->SetText("显示位深4索引png图片 ");
267 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
268
269 UIImageView* imageView = new UIImageView();
270 imageView->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 30); // 30 : offset
271 imageView->SetWidth(50); // 50 : size
272 imageView->SetHeight(50); // 50 : size
273 imageView->SetSrc(PNG_4_PALETTE_IMAGE_PATH);
274 imageView->GetHeight();
275 container_->Add(imageView);
276 g_height += 100; // offset=100
277 }
278 }
279
UIKit_UIImage_Test_SetImage_010()280 void UITestImage::UIKit_UIImage_Test_SetImage_010()
281 {
282 if (container_ != nullptr) {
283 UILabel* label = new UILabel();
284 container_->Add(label);
285 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, Screen::GetInstance().GetWidth(),
286 TITLE_LABEL_DEFAULT_HEIGHT);
287 label->SetText("显示位深8索引png图片 ");
288 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
289
290 UIImageView* imageView = new UIImageView();
291 imageView->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 30); // 30 : offset
292 imageView->SetWidth(50); // 50 : size
293 imageView->SetHeight(50); // 50 : size
294 imageView->SetSrc(PNG_8_PALETTE_IMAGE_PATH);
295 imageView->GetHeight();
296 container_->Add(imageView);
297 g_height += 100; // offset=100
298 }
299 }
300
UIKit_UIImage_Test_SetImage_011()301 void UITestImage::UIKit_UIImage_Test_SetImage_011()
302 {
303 if (container_ != nullptr) {
304 UILabel* label = new UILabel();
305 container_->Add(label);
306 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, Screen::GetInstance().GetWidth(),
307 TITLE_LABEL_DEFAULT_HEIGHT);
308 label->SetText("显示位深24真彩色png图片 ");
309 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
310
311 UIImageView* imageView = new UIImageView();
312 imageView->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 30); // 30 : offset
313 imageView->SetWidth(50); // 50 : size
314 imageView->SetHeight(50); // 50 : size
315 imageView->SetSrc(PNG_24_RGB_IMAGE_PATH);
316 imageView->GetHeight();
317 container_->Add(imageView);
318 g_height += 100; // offset=100
319 }
320 }
321
UIKit_UIImage_Test_SetImage_012()322 void UITestImage::UIKit_UIImage_Test_SetImage_012()
323 {
324 if (container_ != nullptr) {
325 UILabel* label = new UILabel();
326 container_->Add(label);
327 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, Screen::GetInstance().GetWidth(),
328 TITLE_LABEL_DEFAULT_HEIGHT);
329 label->SetText("显示位深32真彩色带Alpha通道png图片 ");
330 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
331
332 UIImageView* imageView = new UIImageView();
333 imageView->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 30); // 30 : offset
334 imageView->SetWidth(50); // 50 : size
335 imageView->SetHeight(50); // 50 : size
336 imageView->SetSrc(PNG_32_RGB_ALPHA_IMAGE_PATH);
337 imageView->GetHeight();
338 container_->Add(imageView);
339 g_height += 100; // offset=100
340 }
341 }
342
UIKit_UIImage_Test_SetImage_013()343 void UITestImage::UIKit_UIImage_Test_SetImage_013()
344 {
345 if (container_ != nullptr) {
346 UILabel* label = new UILabel();
347 container_->Add(label);
348 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, Screen::GetInstance().GetWidth(),
349 TITLE_LABEL_DEFAULT_HEIGHT);
350 label->SetText("显示位深8灰度png图片 ");
351 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
352
353 UIImageView* imageView = new UIImageView();
354 imageView->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 30); // 30 : offset
355 imageView->SetWidth(50); // 50 : size
356 imageView->SetHeight(50); // 50 : size
357 imageView->SetSrc(PNG_8_GRAY_IMAGE_PATH);
358 imageView->GetHeight();
359 container_->Add(imageView);
360 g_height += 100; // offset=100
361 }
362 }
363
UIKit_UIImage_Test_SetImage_014()364 void UITestImage::UIKit_UIImage_Test_SetImage_014()
365 {
366 if (container_ != nullptr) {
367 UILabel* label = new UILabel();
368 container_->Add(label);
369 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, Screen::GetInstance().GetWidth(),
370 TITLE_LABEL_DEFAULT_HEIGHT);
371 label->SetText("显示位深16灰度png图片 ");
372 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
373
374 UIImageView* imageView = new UIImageView();
375 imageView->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 30); // 30 : offset
376 imageView->SetWidth(50); // 50 : size
377 imageView->SetHeight(50); // 50 : size
378 imageView->SetSrc(PNG_16_GRAY_IMAGE_PATH);
379 imageView->GetHeight();
380 container_->Add(imageView);
381 g_height += 100; // offset=100
382 }
383 }
384
385 #if (ENABLE_GIF == 1)
UIKit_UIImage_Test_SetImage_015()386 void UITestImage::UIKit_UIImage_Test_SetImage_015()
387 {
388 if (container_ != nullptr) {
389 UILabel* label = new UILabel();
390 container_->Add(label);
391 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, Screen::GetInstance().GetWidth(),
392 TITLE_LABEL_DEFAULT_HEIGHT);
393 label->SetText("显示gif文件图片 ");
394 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
395
396 UIImageView* imageView = new UIImageView();
397 imageView->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 30); // 30: Y-coordinate
398 imageView->SetSrc(GIF_IMAGE_PATH1);
399 container_->Add(imageView);
400
401 UIImageView* imageView2 = new UIImageView();
402 imageView2->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, g_height + 120); // 120: Y-coordinate
403 imageView2->SetSrc(GIF_IMAGE_PATH2);
404 container_->Add(imageView2);
405 g_height += 180; // offset=180
406 }
407 }
408
UIKit_UIImage_Test_SetImage_016()409 void UITestImage::UIKit_UIImage_Test_SetImage_016()
410 {
411 if (container_ != nullptr) {
412 UILabel* label = new UILabel();
413 container_->Add(label);
414 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, Screen::GetInstance().GetWidth(),
415 TITLE_LABEL_DEFAULT_HEIGHT);
416 label->SetText("不同类型图片切换 ");
417 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
418 gifImageView_ = new UIImageView();
419 gifImageView_->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, 1790); // 1790: Y-coordinate
420 gifImageView_->SetSrc(GIF_IMAGE_PATH1);
421 container_->Add(gifImageView_);
422 gifToGif_ = new UILabelButton();
423 SetUpButton(gifToGif_, "切换GIF");
424 uint16_t gifHeight = g_height + 30; // 30: offset
425 gifToGif_->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, gifHeight);
426 gifToJpeg_ = new UILabelButton();
427 SetUpButton(gifToJpeg_, "切换JPEG");
428 gifToJpeg_->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE + 160, gifHeight); // 160: offset
429 gifToPng_ = new UILabelButton();
430 SetUpButton(gifToPng_, "切换PNG");
431 gifToPng_->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE + 320, gifHeight); // 320: offset
432 gifToBin01_ = new UILabelButton();
433 SetUpButton(gifToBin01_, "切换rgb888");
434 gifToBin01_->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE + 480, gifHeight); // 480: offset
435 gifToBin02_ = new UILabelButton();
436 SetUpButton(gifToBin02_, "ARGB8888bin");
437 gifHeight += 50; // 50: offset
438 gifToBin02_->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, gifHeight);
439 gifToBin03_ = new UILabelButton();
440 SetUpButton(gifToBin03_, "RGB565bin");
441 gifToBin03_->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE + 160, gifHeight); // 160: offset
442 gifToBin04_ = new UILabelButton();
443 SetUpButton(gifToBin04_, "ARGB8888数组");
444 gifToBin04_->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE + 320, gifHeight); // 320: offset
445 g_height += 300; // offset=300
446 }
447 }
448
SetUpButton(UILabelButton * btn,const char * title)449 void UITestImage::SetUpButton(UILabelButton* btn, const char* title)
450 {
451 if (btn == nullptr) {
452 return;
453 }
454 container_->Add(btn);
455 btn->Resize(BUTTON_WIDHT3, BUTTON_HEIGHT3);
456 btn->SetText(title);
457 btn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_LABEL_SIZE);
458 btn->SetOnClickListener(this);
459 btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::RELEASED);
460 btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::PRESSED);
461 btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::INACTIVE);
462 btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::RELEASED);
463 btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::PRESSED);
464 btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::INACTIVE);
465 }
466
OnClick(UIView & view,const ClickEvent & event)467 bool UITestImage::OnClick(UIView &view, const ClickEvent& event)
468 {
469 if (gifImageView_ == nullptr) {
470 return false;
471 }
472 if (&view == gifToGif_) {
473 gifImageView_->SetSrc(GIF_IMAGE_PATH2);
474 } else if (&view == gifToJpeg_) {
475 gifImageView_->SetSrc(JPEG_IMAGE_PATH);
476 } else if (&view == gifToPng_) {
477 gifImageView_->SetSrc(BLUE_IMAGE_PATH);
478 } else if (&view == gifToBin01_) {
479 gifImageView_->SetSrc(BLUE_RGB888_IMAGE_PATH);
480 } else if (&view == gifToBin02_) {
481 gifImageView_->SetSrc(BLUE_ARGB8888_IMAGE_PATH);
482 } else if (&view == gifToBin03_) {
483 gifImageView_->SetSrc(BLUE_RGB565_IMAGE_PATH);
484 } else if (&view == gifToBin04_) {
485 gifImageView_->SetSrc(GetCheckBoxOnInfo());
486 }
487 return true;
488 }
489 #endif
490
UIKit_UIImage_Test_Uncompress_001()491 void UITestImage::UIKit_UIImage_Test_Uncompress_001()
492 {
493 if (container_ != nullptr) {
494 UILabel* label = new UILabel();
495 container_->Add(label);
496 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, Screen::GetInstance().GetWidth(),
497 TITLE_LABEL_DEFAULT_HEIGHT);
498 label->SetText("图片解压测试");
499 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
500
501 UIImageView* imageView1 = new UIImageView();
502 imageView1->SetPosition(48, g_height + 30); // 48 : offset; 30 : offset
503 imageView1->SetSrc(IMAGE_DIR "blue_compress.bin");
504
505 UIImageView* imageView2 = new UIImageView();
506 imageView2->SetPosition(158, g_height + 30); // 158 : offset 30 : offset
507 imageView2->SetSrc(IMAGE_DIR "red_compress.bin");
508
509 UIImageView* imageView3 = new UIImageView();
510 imageView3->SetPosition(268, g_height + 30); // 268 : offset 30 : offset
511 imageView3->SetSrc(IMAGE_DIR "FaultInjection.bin");
512
513 container_->Add(imageView1);
514 container_->Add(imageView2);
515 container_->Add(imageView3);
516 g_height += 150; // offset=150
517 }
518 }
519
AddLable(int16_t x,int16_t y,const char * data)520 UILabel* UITestImage::AddLable(int16_t x, int16_t y, const char* data)
521 {
522 UILabel* label = new UILabel();
523 container_->Add(label);
524 label->SetPosition(x, y, Screen::GetInstance().GetWidth(),
525 TITLE_LABEL_DEFAULT_HEIGHT);
526 label->SetText(data);
527 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
528 return label;
529 }
530
AddImageView(const Rect rect,const char * src,bool autoEnable,UIImageView::ImageResizeMode mode)531 UIImageView* UITestImage::AddImageView(const Rect rect, const char* src, bool autoEnable,
532 UIImageView::ImageResizeMode mode)
533 {
534 UIImageView* imageView = new UIImageView();
535 imageView->SetAutoEnable(autoEnable);
536 imageView->SetPosition(rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight());
537 imageView->SetStyle(STYLE_BORDER_COLOR, Color::Blue().full);
538 imageView->SetStyle(STYLE_BORDER_WIDTH, 1);
539 imageView->SetSrc(src);
540 imageView->SetResizeMode(mode);
541 container_->Add(imageView);
542 return imageView;
543 }
544
UIKit_UIImage_Test_Resize_001()545 void UITestImage::UIKit_UIImage_Test_Resize_001()
546 {
547 if (container_ != nullptr) {
548 AddLable(TEXT_DISTANCE_TO_LEFT_SIDE, g_height, "图片缩放模式测试");
549 constexpr uint16_t STEP = 110; // 110: increase y-coordinate per step
550 const uint16_t LABLE_Y = g_height + 30;
551 const uint16_t IMAGE_Y = g_height + 70;
552 uint16_t x = 40; // 40: the orign x-coordinate
553
554 AddLable(x, LABLE_Y, "Auto");
555 // 100: width and height
556 AddImageView(GetRect(x, IMAGE_Y, 100, 100), IMAGE_RESIZEMODE_PATH, true, UIImageView::ImageResizeMode::NONE);
557
558 x += STEP;
559 AddLable(x, LABLE_Y, "Tiling");
560 // 100: width and height
561 AddImageView(GetRect(x, IMAGE_Y, 100, 100), IMAGE_RESIZEMODE_PATH, false, UIImageView::ImageResizeMode::NONE);
562
563 x += STEP;
564 AddLable(x, LABLE_Y, "Fill");
565 // 100: width and height
566 AddImageView(GetRect(x, IMAGE_Y, 100, 100), IMAGE_RESIZEMODE_PATH, false, UIImageView::ImageResizeMode::FILL);
567
568 x += STEP;
569 AddLable(x, LABLE_Y, "Contain");
570 // 100: width; 50: height
571 AddImageView(GetRect(x, IMAGE_Y, 100, 50), IMAGE_RESIZEMODE_PATH,
572 false, UIImageView::ImageResizeMode::CONTAIN);
573
574 x += STEP;
575 AddLable(x, LABLE_Y, "Cover");
576 // 100: width and height
577 AddImageView(GetRect(x, IMAGE_Y, 100, 100), IMAGE_RESIZEMODE_PATH, false,
578 UIImageView::ImageResizeMode::COVER);
579
580 x += STEP;
581 AddLable(x, LABLE_Y, "Center");
582 // 100: width and height
583 AddImageView(GetRect(x, IMAGE_Y, 100, 100), IMAGE_RESIZEMODE_PATH, false,
584 UIImageView::ImageResizeMode::CENTER);
585
586 x += STEP;
587 AddLable(x, LABLE_Y, "Scale Down");
588 // 100: width and height
589 AddImageView(GetRect(x, IMAGE_Y, 100, 100), IMAGE_RESIZEMODE_PATH, false,
590 UIImageView::ImageResizeMode::SCALE_DOWN);
591 g_height += 200; // offset 200
592 }
593 }
594 } // namespace OHOS
595