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