1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in comliance with the License. 5 * You may obtian 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 "../../dtk_constants.h" 17 18 namespace OHOS { 19 namespace Rosen { 20 21 using namespace Drawing; 22 23 // Pixmap_Scene_0151 24 // Pixmap构造接口:Pixmap_ImageInfo_12 25 // Pixmap操作接口:GetAlphaType 26 // cilp:ClipRoundRect(G2) 27 // transform:ConcatMatrix 28 // 抗锯齿:AA 29 // 透明度:透明 30 // 视效:CreateBlendShader 31 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 1) 32 { 33 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 34 Drawing::Brush brush; 35 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 36 37 // 2.Pixmap构造接口,Pixmap_ImageInfo_12 38 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 39 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 40 colorspace); // 512 width * 512 height 41 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 42 43 // 3.Pixmap操作接口GetAlphaType,绘制部分放到第6步的绘制结果里 44 45 Drawing::Bitmap bitmap1; 46 bitmap1.Build(imageInfo); 47 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 48 bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色 49 50 // 4.组合transform函数ConcatMatrix 51 Drawing::Matrix matrix; 52 matrix.Rotate(15, 10, 10); // 15 angle 10 position 53 playbackCanvas_->ConcatMatrix(matrix); 54 55 brush.SetColor(0xFFFF0000); 56 int rectPos = 0; 57 auto dst = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_RED); 58 auto src = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_GREEN); 59 for (auto BlendMode : blendModes) { 60 auto blendShader = Drawing::ShaderEffect::CreateBlendShader(*dst, *src, BlendMode); 61 // 5.设置视效效果CreateBlendShader,将效果添加到笔刷 62 brush.SetShaderEffect(blendShader); 63 // 6.绘制结果 64 const void* pixel = pixmap.GetAddr(); 65 bitmap1.SetPixels(const_cast<void*>(pixel)); 66 playbackCanvas_->AttachBrush(brush); 67 if (pixmap.GetAlphaType() == Drawing::AlphaType::ALPHATYPE_UNKNOWN) { 68 playbackCanvas_->DrawRect(Drawing::Rect(800 + (rectPos % VARIATION) * LEFT, 69 800 + (rectPos / VARIATION) * LEFT, 1000 + (rectPos % VARIATION) * LEFT, 70 1000 + (rectPos / VARIATION) * LEFT)); // rect region(800, 800, 1000, 1000) 71 } else { 72 playbackCanvas_->DrawRect(Drawing::Rect(1000 + (rectPos % VARIATION) * LEFT, 73 1000 + (rectPos / VARIATION) * LEFT, 1200 + (rectPos % VARIATION) * LEFT, 74 1200 + (rectPos / VARIATION) * LEFT)); // rect region(1000, 1000, 1200, 1200) 75 } 76 playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT, 77 300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap position 78 rectPos += 1; 79 } 80 playbackCanvas_->DetachBrush(); 81 82 // 7.组合Clip函数ClipRoundRect(G2),cilp也有抗锯齿效果,默认和笔刷效果保持一致 83 TestBase::ClipRoundRectG2(true); 84 } 85 86 // Pixmap_Scene_0152 87 // Pixmap构造接口:Pixmap_ImageInfo_12 88 // Pixmap操作接口:GetColorSpace 89 // cilp:ClipRoundRect(G2_capsule) 90 // transform:Rotate 91 // 抗锯齿:非AA 92 // 透明度:半透明 93 // 视效:CreateBlendModeColorFilter 94 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 2) 95 { 96 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:非AA 97 Drawing::Brush brush; 98 brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 99 100 // 2.Pixmap构造接口,Pixmap_ImageInfo_12 101 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 102 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 103 colorspace); // 512 width * 512 height 104 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 105 106 // 3.Pixmap操作接口GetColorSpace,绘制部分放到第6步的绘制结果里 107 108 Drawing::Bitmap bitmap1; 109 bitmap1.Build(imageInfo); 110 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 111 bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色 112 113 // 4.组合transform函数Rotate 114 playbackCanvas_->Rotate(30, 10, 10); // 30 angle 10 position 115 116 brush.SetColor(0xFFFF0000); 117 int rectPos = 0; 118 for (auto blendMode : blendModes) { 119 std::shared_ptr<Drawing::ColorFilter> colorFilter = 120 Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF0000, blendMode); 121 auto filter = Drawing::Filter(); 122 // 5.设置视效效果CreateBlendModeColorFilter,将效果添加到笔刷 123 filter.SetColorFilter(colorFilter); 124 brush.SetFilter(filter); 125 // 6.绘制结果 126 const void* pixel = pixmap.GetAddr(); 127 bitmap1.SetPixels(const_cast<void*>(pixel)); 128 playbackCanvas_->AttachBrush(brush); 129 if (pixmap.GetColorSpace() == colorspace) { 130 playbackCanvas_->DrawRect(Drawing::Rect(800 + (rectPos % VARIATION) * LEFT, 131 800 + (rectPos / VARIATION) * LEFT, 1000 + (rectPos % VARIATION) * LEFT, 132 1000 + (rectPos / VARIATION) * LEFT)); // rect region(800, 800, 1000, 1000) 133 } else { 134 playbackCanvas_->DrawRect(Drawing::Rect(1000 + (rectPos % VARIATION) * LEFT, 135 1000 + (rectPos / VARIATION) * LEFT, 1200 + (rectPos % VARIATION) * LEFT, 136 1200 + (rectPos / VARIATION) * LEFT)); // rect region(1000, 1000, 1200, 1200) 137 } 138 playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT, 139 300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap position 140 rectPos += 1; 141 } 142 playbackCanvas_->DetachBrush(); 143 144 // 7.组合Clip函数ClipRoundRect(G2_capsule),cilp也有抗锯齿效果,默认和笔刷效果保持一致 145 TestBase::ClipRoundRectG2capsule(false); 146 } 147 148 // Pixmap_Scene_0153 149 // Pixmap构造接口:Pixmap_ImageInfo_12 150 // Pixmap操作接口:GetRowBytes 151 // cilp:ClipRoundRect(非G2) 152 // transform:Scale(正常值) 153 // 抗锯齿:AA 154 // 透明度:不透明 155 // 视效:CreateBlurImageFilter 156 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 3) 157 { 158 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 159 Drawing::Brush brush; 160 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 161 162 // 2.Pixmap构造接口,Pixmap_ImageInfo_12 163 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 164 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 165 colorspace); // 512 width * 512 height 166 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 167 168 // 3.Pixmap操作接口GetRowBytes,绘制部分放到第6步的绘制结果里 169 ImageInfo imageInfo1(1, 1, COLORTYPE_RGBA_8888, ALPHATYPE_PREMUL); 170 uint32_t pixel[] = { 0xFF123456 }; 171 Pixmap pixmap1(imageInfo1, pixel, sizeof(pixel)); 172 std::shared_ptr<Data> data = std::make_shared<Data>(); 173 data->BuildWithCopy(pixmap1.GetAddr(), pixmap1.GetRowBytes() * pixmap1.GetHeight()); 174 auto image = Image::MakeRasterData(imageInfo1, data, pixmap1.GetRowBytes()); 175 176 Drawing::Bitmap bitmap1; 177 bitmap1.Build(imageInfo); 178 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 179 bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色 180 181 // 4.设置视效效果CreateBlurImageFilter,将效果添加到笔刷 182 brush.SetColor(0xFFFF0000); 183 auto filter = Drawing::Filter(); 184 filter.SetImageFilter(Drawing::ImageFilter::CreateBlurImageFilter( 185 10.0f, 10.0f, Drawing::TileMode::CLAMP, nullptr, Drawing::ImageBlurType::GAUSS)); 186 brush.SetFilter(filter); 187 188 // 5.组合transform函数Scale(正常值) 189 playbackCanvas_->Scale(2.0f, 2.0f); // ratio 190 191 // 6.绘制结果 192 const void* pixel1 = pixmap.GetAddr(); 193 bitmap1.SetPixels(const_cast<void*>(pixel1)); 194 playbackCanvas_->AttachBrush(brush); 195 playbackCanvas_->DrawImageNine(image.get(), Drawing::RectI(0, 0, 1, 1), 196 Rect(100, 100, 500, 500), // Rect(100, 100, 500, 500) & RectI(0, 0, 1, 1) 197 FilterMode::NEAREST); 198 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 199 playbackCanvas_->DetachBrush(); 200 201 // 7.组合Clip函数ClipRoundRect(非G2),cilp也有抗锯齿效果,默认和笔刷效果保持一致 202 TestBase::ClipRoundRectnotG2(true); 203 } 204 205 // Pixmap_Scene_0154 206 // Pixmap构造接口:Pixmap_ImageInfo_12 207 // Pixmap操作接口:GetAddr 208 // cilp:ClipRoundRect(G2_capsule) 209 // transform:Scale(极大值) 210 // 抗锯齿:非AA 211 // 透明度:透明 212 // 视效:CreateLinearToSrgbGamma 213 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 4) 214 { 215 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:非AA 216 Drawing::Brush brush; 217 brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 218 219 // 2.Pixmap构造接口,Pixmap_ImageInfo_12 220 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 221 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 222 colorspace); // 512 width * 512 height 223 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 224 225 // 3.Pixmap操作接口GetAddr,绘制部分放到第6步的绘制结果里 226 227 Drawing::Bitmap bitmap1; 228 bitmap1.Build(imageInfo); 229 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 230 bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色 231 232 // 4.设置视效效果CreateLinearToSrgbGamma,将效果添加到笔刷 233 brush.SetColor(0xFF4F7091); 234 auto filter = Drawing::Filter(); 235 filter.SetColorFilter(Drawing::ColorFilter::CreateLinearToSrgbGamma()); 236 brush.SetFilter(filter); 237 238 // 5.组合transform函数Scale(极大值) 239 playbackCanvas_->Scale(1.0f, 10100.0f); // ratio 240 241 // 6.绘制结果 242 const void* pixel = pixmap.GetAddr(); 243 bitmap1.SetPixels(const_cast<void*>(pixel)); 244 playbackCanvas_->AttachBrush(brush); 245 playbackCanvas_->DrawBitmap(bitmap1, 300, 300); // 300,300 is bitmap position 246 playbackCanvas_->DetachBrush(); 247 248 // 7.组合Clip函数ClipRoundRect(G2_capsule),cilp也有抗锯齿效果,默认和笔刷效果保持一致 249 TestBase::ClipRoundRectG2capsule(false); 250 } 251 252 // Pixmap_Scene_0155 253 // Pixmap构造接口:Pixmap_ImageInfo_12 254 // Pixmap操作接口:GetColor 255 // cilp:ClipRect 256 // transform:Scale(极大值) 257 // 抗锯齿:非AA 258 // 透明度:半透明 259 // 视效:CreateColorShader 260 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 5) 261 { 262 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:非AA 263 Drawing::Brush brush; 264 brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 265 266 // 2.Pixmap构造接口,Pixmap_ImageInfo_12 267 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 268 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 269 colorspace); // 512 width * 512 height 270 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 271 272 // 3.Pixmap操作接口GetColor,绘制部分放到第6步的绘制结果里 273 Drawing::Pen pen; 274 pen.SetWidth(8.5f); 275 pen.SetColor(pixmap.GetColor(imageInfo.GetWidth() / 2, imageInfo.GetHeight() / 2)); 276 277 Drawing::Bitmap bitmap1; 278 bitmap1.Build(imageInfo); 279 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 280 bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色 281 282 // 4.设置视效效果CreateColorShader,将效果添加到笔刷 283 brush.SetColor(0xFFFF0000); 284 auto colorShader = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_RED); 285 brush.SetShaderEffect(colorShader); 286 287 // 5.组合transform函数Scale(极大值) 288 playbackCanvas_->Scale(1.0f, 10100.0f); // ratio 289 290 // 6.绘制结果 291 const void* pixel = pixmap.GetAddr(); 292 bitmap1.SetPixels(const_cast<void*>(pixel)); 293 playbackCanvas_->AttachBrush(brush); 294 playbackCanvas_->AttachPen(pen); 295 auto p1 = Drawing::Point(800, 800); // point position(800, 800) 296 auto p2 = Drawing::Point(1000, 1000); // point position(1000, 1000) 297 playbackCanvas_->DrawLine(p1, p2); 298 playbackCanvas_->DetachPen(); 299 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 300 playbackCanvas_->DetachBrush(); 301 302 // 7.组合Clip函数ClipRect,cilp也有抗锯齿效果,默认和笔刷效果保持一致 303 TestBase::ClipRect(false); 304 } 305 306 // Pixmap_Scene_0156 307 // Pixmap构造接口:Pixmap_ImageInfo_12 308 // Pixmap操作接口:GetColor 309 // cilp:ClipRoundRect(非G2) 310 // transform:Scale(极小值) 311 // 抗锯齿:AA 312 // 透明度:半透明 313 // 视效:CreateMatrixColorFilter 314 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 6) 315 { 316 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 317 Drawing::Brush brush; 318 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 319 320 // 2.Pixmap构造接口,Pixmap_ImageInfo_12 321 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 322 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 323 colorspace); // 512 width * 512 height 324 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 325 326 // 3.Pixmap操作接口GetColor,绘制部分放到第6步的绘制结果里 327 Drawing::Pen pen; 328 pen.SetWidth(8.5f); 329 pen.SetColor(pixmap.GetColor(imageInfo.GetWidth() / 2, imageInfo.GetHeight() / 2)); 330 331 Drawing::Bitmap bitmap1; 332 bitmap1.Build(imageInfo); 333 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 334 bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色 335 336 // 4.设置视效效果CreateMatrixColorFilter,将效果添加到笔刷 337 Drawing::ColorMatrix matrix; 338 matrix.SetArray(ARR); 339 auto cf = Drawing::ColorFilter::CreateMatrixColorFilter(matrix); 340 auto filter = Drawing::Filter(); 341 filter.SetImageFilter(Drawing::ImageFilter::CreateColorFilterImageFilter(*cf, nullptr)); 342 brush.SetFilter(filter); 343 344 // 5.组合transform函数Scale(极小值) 345 playbackCanvas_->Scale(10100.0f, 1.0f); // ratio 346 347 // 6.绘制结果 348 const void* pixel = pixmap.GetAddr(); 349 bitmap1.SetPixels(const_cast<void*>(pixel)); 350 playbackCanvas_->AttachBrush(brush); 351 playbackCanvas_->AttachPen(pen); 352 auto p1 = Drawing::Point(800, 800); // point position(800, 800) 353 auto p2 = Drawing::Point(1000, 1000); // point position(1000, 1000) 354 playbackCanvas_->DrawLine(p1, p2); 355 playbackCanvas_->DetachPen(); 356 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 357 playbackCanvas_->DetachBrush(); 358 359 // 7.组合Clip函数ClipRoundRect(非G2),cilp也有抗锯齿效果,默认和笔刷效果保持一致 360 TestBase::ClipRoundRectnotG2(true); 361 } 362 363 // Pixmap_Scene_0157 364 // Pixmap构造接口:Pixmap_ImageInfo_12 365 // Pixmap操作接口:ScalePixels 366 // cilp:ClipRoundRect(G2) 367 // transform:Scale(极小值) 368 // 抗锯齿:AA 369 // 透明度:不透明 370 // 视效:CreateComposeColorFilter 371 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 7) 372 { 373 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 374 Drawing::Brush brush; 375 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 376 377 // 2.Pixmap构造接口,Pixmap_ImageInfo_12 378 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 379 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 380 colorspace); // 512 width * 512 height 381 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 382 383 // 3.Pixmap操作接口ScalePixels,绘制部分放到第6步的绘制结果里 384 ImageInfo imageinfo2 = ImageInfo::MakeN32Premul(4, 4); // pixel row and col(4, 4) 385 uint32_t data[16]; 386 Pixmap dst(imageinfo2, data, sizeof(uint32_t) * imageinfo2.GetWidth()); 387 388 Drawing::Bitmap bitmap1; 389 bitmap1.Build(imageInfo); 390 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 391 bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色 392 393 // 4.设置视效效果CreateComposeColorFilter,将效果添加到笔刷 394 brush.SetColor(0xFFFF0000); 395 std::shared_ptr<Drawing::ColorFilter> colorFilter1 = 396 Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF0000, Drawing::BlendMode::SRC_IN); 397 std::shared_ptr<Drawing::ColorFilter> colorFilter2 = 398 Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF00FF, Drawing::BlendMode::MODULATE); 399 std::shared_ptr<Drawing::ColorFilter> colorFilter3 = 400 Drawing::ColorFilter::CreateComposeColorFilter(*colorFilter1, *colorFilter2); 401 auto filter = Drawing::Filter(); 402 filter.SetColorFilter(colorFilter3); 403 brush.SetFilter(filter); 404 405 // 5.组合transform函数Scale(极小值) 406 playbackCanvas_->Scale(10100.0f, 1.0f); // ratio 407 408 // 6.绘制结果 409 const void* pixel = pixmap.GetAddr(); 410 bitmap1.SetPixels(const_cast<void*>(pixel)); 411 playbackCanvas_->AttachBrush(brush); 412 if (pixmap.ScalePixels(dst, SamplingOptions())) { 413 playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000) 414 } else { 415 playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200) 416 } 417 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 418 playbackCanvas_->DetachBrush(); 419 420 // 7.组合Clip函数ClipRoundRect(G2),cilp也有抗锯齿效果,默认和笔刷效果保持一致 421 TestBase::ClipRoundRectG2(true); 422 } 423 424 // Pixmap_Scene_0158 425 // Pixmap构造接口:Pixmap_ImageInfo_12 426 // Pixmap操作接口:ScalePixels 427 // cilp:null 428 // transform:Scale(正常值) 429 // 抗锯齿:非AA 430 // 透明度:不透明 431 // 视效:CreateLinearToSrgbGamma 432 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 8) 433 { 434 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:非AA 435 Drawing::Brush brush; 436 brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 437 438 // 2.Pixmap构造接口,Pixmap_ImageInfo_12 439 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 440 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 441 colorspace); // 512 width * 512 height 442 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 443 444 // 3.Pixmap操作接口ScalePixels,绘制部分放到第6步的绘制结果里 445 ImageInfo imageinfo2 = ImageInfo::MakeN32Premul(4, 4); // pixel row and col(4, 4) 446 uint32_t data[16]; 447 Pixmap dst(imageinfo2, data, sizeof(uint32_t) * imageinfo2.GetWidth()); 448 449 Drawing::Bitmap bitmap1; 450 bitmap1.Build(imageInfo); 451 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 452 bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色 453 454 // 4.设置视效效果CreateLinearToSrgbGamma,将效果添加到笔刷 455 brush.SetColor(0xFF4F7091); 456 auto filter = Drawing::Filter(); 457 filter.SetColorFilter(Drawing::ColorFilter::CreateLinearToSrgbGamma()); 458 brush.SetFilter(filter); 459 460 // 5.组合transform函数Scale(正常值) 461 playbackCanvas_->Scale(2.0f, 2.0f); // ratio 462 463 // 6.绘制结果 464 const void* pixel = pixmap.GetAddr(); 465 bitmap1.SetPixels(const_cast<void*>(pixel)); 466 playbackCanvas_->AttachBrush(brush); 467 if (pixmap.ScalePixels(dst, SamplingOptions())) { 468 playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000) 469 } else { 470 playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200) 471 } 472 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 473 playbackCanvas_->DetachBrush(); 474 475 // 7.无Clip函数 476 } 477 478 // Pixmap_Scene_0159 479 // Pixmap构造接口:Pixmap_ImageInfo_13 480 // Pixmap操作接口:GetWidth 481 // cilp:ClipRoundRect(G2) 482 // transform:Shear 483 // 抗锯齿:AA 484 // 透明度:不透明 485 // 视效:CreateBlendShader 486 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 9) 487 { 488 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 489 Drawing::Brush brush; 490 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 491 492 // 2.Pixmap构造接口,Pixmap_ImageInfo_13 493 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 494 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_BGRA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 495 colorspace); // 512 width * 512 height 496 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 497 498 // 3.Pixmap操作接口GetWidth,绘制部分放到第6步的绘制结果里 499 auto width = pixmap.GetWidth(); 500 501 Drawing::Bitmap bitmap1; 502 bitmap1.Build(imageInfo); 503 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 504 bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色 505 506 // 4.组合transform函数Shear 507 playbackCanvas_->Shear(10.0f, 10.0f); // slope 508 509 brush.SetColor(0xFFFF0000); 510 int rectPos = 0; 511 auto dst = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_RED); 512 auto src = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_GREEN); 513 for (auto BlendMode : blendModes) { 514 auto blendShader = Drawing::ShaderEffect::CreateBlendShader(*dst, *src, BlendMode); 515 // 5.设置视效效果CreateBlendShader,将效果添加到笔刷 516 brush.SetShaderEffect(blendShader); 517 // 6.绘制结果 518 const void* pixel = pixmap.GetAddr(); 519 bitmap1.SetPixels(const_cast<void*>(pixel)); 520 playbackCanvas_->AttachBrush(brush); 521 playbackCanvas_->DrawRect(Rect(0 + (rectPos % VARIATION) * LEFT, 0 + (rectPos / VARIATION) * LEFT, 522 width + (rectPos % VARIATION) * LEFT, 500 + (rectPos / VARIATION) * LEFT)); // width * 500 height 523 playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT, 524 300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap position 525 rectPos += 1; 526 } 527 playbackCanvas_->DetachBrush(); 528 529 // 7.组合Clip函数ClipRoundRect(G2),cilp也有抗锯齿效果,默认和笔刷效果保持一致 530 TestBase::ClipRoundRectG2(true); 531 } 532 533 // Pixmap_Scene_0160 534 // Pixmap构造接口:Pixmap_ImageInfo_13 535 // Pixmap操作接口:GetHeight 536 // cilp:ClipRoundRect(G2_capsule) 537 // transform:null 538 // 抗锯齿:非AA 539 // 透明度:透明 540 // 视效:CreateLumaColorFilter 541 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 10) 542 { 543 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:非AA 544 Drawing::Brush brush; 545 brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 546 547 // 2.Pixmap构造接口,Pixmap_ImageInfo_13 548 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 549 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_BGRA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 550 colorspace); // 512 width * 512 height 551 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 552 553 // 3.Pixmap操作接口GetHeight,绘制部分放到第6步的绘制结果里 554 auto height = pixmap.GetHeight(); 555 556 Drawing::Bitmap bitmap1; 557 bitmap1.Build(imageInfo); 558 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 559 bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色 560 561 // 4.设置视效效果CreateLumaColorFilter,将效果添加到笔刷 562 brush.SetColor(0xFF0000FF); 563 auto filter = Drawing::Filter(); 564 filter.SetColorFilter(Drawing::ColorFilter::CreateLumaColorFilter()); 565 brush.SetFilter(filter); 566 567 // 5.无transform函数 568 // 6.绘制结果 569 const void* pixel = pixmap.GetAddr(); 570 bitmap1.SetPixels(const_cast<void*>(pixel)); 571 playbackCanvas_->AttachBrush(brush); 572 playbackCanvas_->DrawRect(Rect(0, 0, 500, height)); // 500 width * height 573 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 574 playbackCanvas_->DetachBrush(); 575 576 // 7.组合Clip函数ClipRoundRect(G2_capsule),cilp也有抗锯齿效果,默认和笔刷效果保持一致 577 TestBase::ClipRoundRectG2capsule(false); 578 } 579 580 // Pixmap_Scene_0161 581 // Pixmap构造接口:Pixmap_ImageInfo_13 582 // Pixmap操作接口:GetColorType 583 // cilp:ClipRoundRect(非G2) 584 // transform:ConcatMatrix 585 // 抗锯齿:AA 586 // 透明度:半透明 587 // 视效:CreateBlurMaskFilter 588 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 11) 589 { 590 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 591 Drawing::Brush brush; 592 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 593 594 // 2.Pixmap构造接口,Pixmap_ImageInfo_13 595 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 596 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_BGRA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 597 colorspace); // 512 width * 512 height 598 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 599 600 // 3.Pixmap操作接口GetColorType,绘制部分放到第6步的绘制结果里 601 602 Drawing::Bitmap bitmap1; 603 bitmap1.Build(imageInfo); 604 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 605 bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色 606 607 // 4.组合transform函数ConcatMatrix 608 Drawing::Matrix matrix; 609 matrix.Rotate(15, 10, 10); // 15 angle 10 position 610 playbackCanvas_->ConcatMatrix(matrix); 611 612 brush.SetColor(0xFFFF0000); 613 int rectPos = 0; 614 for (auto& blurType : blurTypes) { 615 auto filter = Drawing::Filter(); 616 // 5.设置视效效果CreateBlurMaskFilter,将效果添加到笔刷 617 filter.SetMaskFilter(Drawing::MaskFilter::CreateBlurMaskFilter(blurType, 10.0f, true)); 618 brush.SetFilter(filter); 619 // 6.绘制结果 620 const void* pixel = pixmap.GetAddr(); 621 bitmap1.SetPixels(const_cast<void*>(pixel)); 622 playbackCanvas_->AttachBrush(brush); 623 if (pixmap.GetColorType() == Drawing::ColorType::COLORTYPE_BGRA_8888) { 624 playbackCanvas_->DrawRect(Drawing::Rect(800 + (rectPos % VARIATION) * LEFT, 625 800 + (rectPos / VARIATION) * LEFT, 1000 + (rectPos % VARIATION) * LEFT, 626 1000 + (rectPos / VARIATION) * LEFT)); // rect region(800, 800, 1000, 1000) 627 } else { 628 playbackCanvas_->DrawRect(Drawing::Rect(1000 + (rectPos % VARIATION) * LEFT, 629 1000 + (rectPos / VARIATION) * LEFT, 1200 + (rectPos % VARIATION) * LEFT, 630 1200 + (rectPos / VARIATION) * LEFT)); // rect region(1000, 1000, 1200, 1200) 631 } 632 playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT, 633 300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap position 634 rectPos += 200; 635 } 636 playbackCanvas_->DetachBrush(); 637 638 // 7.组合Clip函数ClipRoundRect(非G2),cilp也有抗锯齿效果,默认和笔刷效果保持一致 639 TestBase::ClipRoundRectnotG2(true); 640 } 641 642 // Pixmap_Scene_0162 643 // Pixmap构造接口:Pixmap_ImageInfo_13 644 // Pixmap操作接口:GetAlphaType 645 // cilp:ClipPath 646 // transform:ConcatMatrix 647 // 抗锯齿:AA 648 // 透明度:透明 649 // 视效:CreateLinearGradient 650 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 12) 651 { 652 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 653 Drawing::Brush brush; 654 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 655 656 // 2.Pixmap构造接口,Pixmap_ImageInfo_13 657 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 658 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_BGRA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 659 colorspace); // 512 width * 512 height 660 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 661 662 // 3.Pixmap操作接口GetAlphaType,绘制部分放到第6步的绘制结果里 663 664 Drawing::Bitmap bitmap1; 665 bitmap1.Build(imageInfo); 666 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 667 bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色 668 669 // 4.设置视效效果CreateLinearGradient,将效果添加到笔刷 670 std::vector<Drawing::ColorQuad> colors = { Drawing::Color::COLOR_RED, Drawing::Color::COLOR_GREEN, 671 Drawing::Color::COLOR_BLUE }; 672 std::vector<Drawing::scalar> pos = { 0.00f, 0.50f, 1.00f }; 673 auto linearGradient = Drawing::ShaderEffect::CreateLinearGradient( 674 { 0, 0 }, { 1000, 1000 }, colors, pos, Drawing::TileMode::CLAMP); // 0 start pos & 1000 end pos 675 brush.SetShaderEffect(linearGradient); 676 677 // 5.组合transform函数ConcatMatrix 678 Drawing::Matrix matrix; 679 matrix.Rotate(15, 10, 10); // 15 angle 10 position 680 playbackCanvas_->ConcatMatrix(matrix); 681 682 // 6.绘制结果 683 const void* pixel = pixmap.GetAddr(); 684 bitmap1.SetPixels(const_cast<void*>(pixel)); 685 playbackCanvas_->AttachBrush(brush); 686 if (pixmap.GetAlphaType() == Drawing::AlphaType::ALPHATYPE_UNKNOWN) { 687 playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000) 688 } else { 689 playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200) 690 } 691 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 692 playbackCanvas_->DetachBrush(); 693 694 // 7.组合Clip函数ClipPath,cilp也有抗锯齿效果,默认和笔刷效果保持一致 695 TestBase::ClipPath(true); 696 } 697 698 // Pixmap_Scene_0163 699 // Pixmap构造接口:Pixmap_ImageInfo_13 700 // Pixmap操作接口:GetAlphaType 701 // cilp:null 702 // transform:Rotate 703 // 抗锯齿:非AA 704 // 透明度:透明 705 // 视效:CreateBlendImageFilter 706 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 13) 707 { 708 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:非AA 709 Drawing::Brush brush; 710 brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 711 712 // 2.Pixmap构造接口,Pixmap_ImageInfo_13 713 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 714 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_BGRA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 715 colorspace); // 512 width * 512 height 716 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 717 718 // 3.Pixmap操作接口GetAlphaType,绘制部分放到第6步的绘制结果里 719 720 Drawing::Bitmap bitmap1; 721 bitmap1.Build(imageInfo); 722 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 723 bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色 724 725 // 4.组合transform函数Rotate 726 playbackCanvas_->Rotate(30, 10, 10); // 30 angle 10 position 727 728 brush.SetColor(0x4CB21933); 729 int rectPos = 0; 730 for (auto blendMode : blendModes) { 731 auto background = Drawing::ImageFilter::CreateBlurImageFilter( 732 1.0f, 1.0f, Drawing::TileMode::REPEAT, nullptr, Drawing::ImageBlurType::GAUSS); 733 auto foreground = Drawing::ImageFilter::CreateBlurImageFilter( 734 1.0f, 1.0f, Drawing::TileMode::REPEAT, nullptr, Drawing::ImageBlurType::GAUSS); 735 auto filter = Drawing::Filter(); 736 // 5.设置视效效果CreateBlendImageFilter,将效果添加到笔刷 737 filter.SetImageFilter(Drawing::ImageFilter::CreateBlendImageFilter(blendMode, background, foreground)); 738 brush.SetFilter(filter); 739 740 // 6.绘制结果 741 const void* pixel = pixmap.GetAddr(); 742 bitmap1.SetPixels(const_cast<void*>(pixel)); 743 playbackCanvas_->Save(); 744 playbackCanvas_->AttachBrush(brush); 745 if (pixmap.GetAlphaType() == Drawing::AlphaType::ALPHATYPE_UNKNOWN) { 746 playbackCanvas_->DrawRect(Drawing::Rect(800 + (rectPos % VARIATION) * LEFT, 747 800 + (rectPos / VARIATION) * LEFT, 1000 + (rectPos % VARIATION) * LEFT, 748 1000 + (rectPos / VARIATION) * LEFT)); // rect region(800, 800, 1000, 1000) 749 } else { 750 playbackCanvas_->DrawRect(Drawing::Rect(1000 + (rectPos % VARIATION) * LEFT, 751 1000 + (rectPos / VARIATION) * LEFT, 1200 + (rectPos % VARIATION) * LEFT, 752 1200 + (rectPos / VARIATION) * LEFT)); // rect region(1000, 1000, 1200, 1200) 753 } 754 playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT, 755 300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap position 756 playbackCanvas_->Restore(); 757 rectPos += 1; 758 } 759 playbackCanvas_->DetachBrush(); 760 761 // 7.无Clip函数 762 } 763 764 // Pixmap_Scene_0164 765 // Pixmap构造接口:Pixmap_ImageInfo_13 766 // Pixmap操作接口:GetColorSpace 767 // cilp:ClipPath 768 // transform:Scale(正常值) 769 // 抗锯齿:AA 770 // 透明度:半透明 771 // 视效:CreateBlurMaskFilter 772 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 14) 773 { 774 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 775 Drawing::Brush brush; 776 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 777 778 // 2.Pixmap构造接口,Pixmap_ImageInfo_13 779 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 780 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_BGRA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 781 colorspace); // 512 width * 512 height 782 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 783 784 // 3.Pixmap操作接口GetColorSpace,绘制部分放到第6步的绘制结果里 785 786 Drawing::Bitmap bitmap1; 787 bitmap1.Build(imageInfo); 788 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 789 bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色 790 791 // 4.组合transform函数Scale(正常值) 792 playbackCanvas_->Scale(2.0f, 2.0f); // ratio 793 794 brush.SetColor(0xFFFF0000); 795 int rectPos = 0; 796 for (auto& blurType : blurTypes) { 797 auto filter = Drawing::Filter(); 798 // 5.设置视效效果CreateBlurMaskFilter,将效果添加到笔刷 799 filter.SetMaskFilter(Drawing::MaskFilter::CreateBlurMaskFilter(blurType, 10.0f, true)); 800 brush.SetFilter(filter); 801 // 6.绘制结果 802 const void* pixel = pixmap.GetAddr(); 803 bitmap1.SetPixels(const_cast<void*>(pixel)); 804 playbackCanvas_->AttachBrush(brush); 805 if (pixmap.GetColorSpace() == colorspace) { 806 playbackCanvas_->DrawRect(Drawing::Rect(800 + (rectPos % VARIATION) * LEFT, 807 800 + (rectPos / VARIATION) * LEFT, 1000 + (rectPos % VARIATION) * LEFT, 808 1000 + (rectPos / VARIATION) * LEFT)); // rect region(800, 800, 1000, 1000) 809 } else { 810 playbackCanvas_->DrawRect(Drawing::Rect(1000 + (rectPos % VARIATION) * LEFT, 811 1000 + (rectPos / VARIATION) * LEFT, 1200 + (rectPos % VARIATION) * LEFT, 812 1200 + (rectPos / VARIATION) * LEFT)); // rect region(1000, 1000, 1200, 1200) 813 } 814 playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT, 815 300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap position 816 rectPos += 200; 817 } 818 playbackCanvas_->DetachBrush(); 819 820 // 7.组合Clip函数ClipPath,cilp也有抗锯齿效果,默认和笔刷效果保持一致 821 TestBase::ClipPath(true); 822 } 823 824 // Pixmap_Scene_0165 825 // Pixmap构造接口:Pixmap_ImageInfo_13 826 // Pixmap操作接口:GetColorSpace 827 // cilp:ClipRect 828 // transform:Rotate 829 // 抗锯齿:非AA 830 // 透明度:半透明 831 // 视效:CreateBlendModeColorFilter 832 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 15) 833 { 834 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:非AA 835 Drawing::Brush brush; 836 brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 837 838 // 2.Pixmap构造接口,Pixmap_ImageInfo_13 839 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 840 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_BGRA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 841 colorspace); // 512 width * 512 height 842 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 843 844 // 3.Pixmap操作接口GetColorSpace,绘制部分放到第6步的绘制结果里 845 846 Drawing::Bitmap bitmap1; 847 bitmap1.Build(imageInfo); 848 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 849 bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色 850 851 // 4.组合transform函数Rotate 852 playbackCanvas_->Rotate(30, 10, 10); // 30 angle 10 position 853 854 brush.SetColor(0xFFFF0000); 855 int rectPos = 0; 856 for (auto blendMode : blendModes) { 857 std::shared_ptr<Drawing::ColorFilter> colorFilter = 858 Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF0000, blendMode); 859 auto filter = Drawing::Filter(); 860 // 5.设置视效效果CreateBlendModeColorFilter,将效果添加到笔刷 861 filter.SetColorFilter(colorFilter); 862 brush.SetFilter(filter); 863 // 6.绘制结果 864 const void* pixel = pixmap.GetAddr(); 865 bitmap1.SetPixels(const_cast<void*>(pixel)); 866 playbackCanvas_->AttachBrush(brush); 867 if (pixmap.GetColorSpace() == colorspace) { 868 playbackCanvas_->DrawRect(Drawing::Rect(800 + (rectPos % VARIATION) * LEFT, 869 800 + (rectPos / VARIATION) * LEFT, 1000 + (rectPos % VARIATION) * LEFT, 870 1000 + (rectPos / VARIATION) * LEFT)); // rect region(800, 800, 1000, 1000) 871 } else { 872 playbackCanvas_->DrawRect(Drawing::Rect(1000 + (rectPos % VARIATION) * LEFT, 873 1000 + (rectPos / VARIATION) * LEFT, 1200 + (rectPos % VARIATION) * LEFT, 874 1200 + (rectPos / VARIATION) * LEFT)); // rect region(1000, 1000, 1200, 1200) 875 } 876 playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT, 877 300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap position 878 rectPos += 1; 879 } 880 playbackCanvas_->DetachBrush(); 881 882 // 7.组合Clip函数ClipRect,cilp也有抗锯齿效果,默认和笔刷效果保持一致 883 TestBase::ClipRect(false); 884 } 885 886 // Pixmap_Scene_0166 887 // Pixmap构造接口:Pixmap_ImageInfo_13 888 // Pixmap操作接口:GetRowBytes 889 // cilp:ClipRect 890 // transform:Scale(极大值) 891 // 抗锯齿:非AA 892 // 透明度:不透明 893 // 视效:CreateBlurImageFilter 894 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 16) 895 { 896 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:非AA 897 Drawing::Brush brush; 898 brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 899 900 // 2.Pixmap构造接口,Pixmap_ImageInfo_13 901 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 902 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_BGRA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 903 colorspace); // 512 width * 512 height 904 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 905 906 // 3.Pixmap操作接口GetRowBytes,绘制部分放到第6步的绘制结果里 907 ImageInfo imageInfo1(1, 1, COLORTYPE_RGBA_8888, ALPHATYPE_PREMUL); 908 uint32_t pixel[] = { 0xFF123456 }; 909 Pixmap pixmap1(imageInfo1, pixel, sizeof(pixel)); 910 std::shared_ptr<Data> data = std::make_shared<Data>(); 911 data->BuildWithCopy(pixmap1.GetAddr(), pixmap1.GetRowBytes() * pixmap1.GetHeight()); 912 auto image = Image::MakeRasterData(imageInfo1, data, pixmap1.GetRowBytes()); 913 914 Drawing::Bitmap bitmap1; 915 bitmap1.Build(imageInfo); 916 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 917 bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色 918 919 // 4.设置视效效果CreateBlurImageFilter,将效果添加到笔刷 920 brush.SetColor(0xFFFF0000); 921 auto filter = Drawing::Filter(); 922 filter.SetImageFilter(Drawing::ImageFilter::CreateBlurImageFilter( 923 10.0f, 10.0f, Drawing::TileMode::CLAMP, nullptr, Drawing::ImageBlurType::GAUSS)); 924 brush.SetFilter(filter); 925 926 // 5.组合transform函数Scale(极大值) 927 playbackCanvas_->Scale(1.0f, 10100.0f); // ratio 928 929 // 6.绘制结果 930 const void* pixel1 = pixmap.GetAddr(); 931 bitmap1.SetPixels(const_cast<void*>(pixel1)); 932 playbackCanvas_->AttachBrush(brush); 933 playbackCanvas_->DrawImageNine(image.get(), Drawing::RectI(0, 0, 1, 1), 934 Rect(100, 100, 500, 500), // Rect(100, 100, 500, 500) & RectI(0, 0, 1, 1) 935 FilterMode::NEAREST); 936 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 937 playbackCanvas_->DetachBrush(); 938 939 // 7.组合Clip函数ClipRect,cilp也有抗锯齿效果,默认和笔刷效果保持一致 940 TestBase::ClipRect(false); 941 } 942 943 // Pixmap_Scene_0167 944 // Pixmap构造接口:Pixmap_ImageInfo_13 945 // Pixmap操作接口:GetRowBytes 946 // cilp:ClipRoundRect(G2) 947 // transform:Scale(正常值) 948 // 抗锯齿:AA 949 // 透明度:不透明 950 // 视效:CreateMatrixColorFilter 951 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 17) 952 { 953 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 954 Drawing::Brush brush; 955 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 956 957 // 2.Pixmap构造接口,Pixmap_ImageInfo_13 958 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 959 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_BGRA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 960 colorspace); // 512 width * 512 height 961 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 962 963 // 3.Pixmap操作接口GetRowBytes,绘制部分放到第6步的绘制结果里 964 ImageInfo imageInfo1(1, 1, COLORTYPE_RGBA_8888, ALPHATYPE_PREMUL); 965 uint32_t pixel[] = { 0xFF123456 }; 966 Pixmap pixmap1(imageInfo1, pixel, sizeof(pixel)); 967 std::shared_ptr<Data> data = std::make_shared<Data>(); 968 data->BuildWithCopy(pixmap1.GetAddr(), pixmap1.GetRowBytes() * pixmap1.GetHeight()); 969 auto image = Image::MakeRasterData(imageInfo1, data, pixmap1.GetRowBytes()); 970 971 Drawing::Bitmap bitmap1; 972 bitmap1.Build(imageInfo); 973 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 974 bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色 975 976 // 4.设置视效效果CreateMatrixColorFilter,将效果添加到笔刷 977 Drawing::ColorMatrix matrix; 978 matrix.SetArray(ARR); 979 auto cf = Drawing::ColorFilter::CreateMatrixColorFilter(matrix); 980 auto filter = Drawing::Filter(); 981 filter.SetImageFilter(Drawing::ImageFilter::CreateColorFilterImageFilter(*cf, nullptr)); 982 brush.SetFilter(filter); 983 984 // 5.组合transform函数Scale(正常值) 985 playbackCanvas_->Scale(2.0f, 2.0f); // ratio 986 987 // 6.绘制结果 988 const void* pixel1 = pixmap.GetAddr(); 989 bitmap1.SetPixels(const_cast<void*>(pixel1)); 990 playbackCanvas_->AttachBrush(brush); 991 playbackCanvas_->DrawImageNine(image.get(), Drawing::RectI(0, 0, 1, 1), 992 Rect(100, 100, 500, 500), // Rect(100, 100, 500, 500) & RectI(0, 0, 1, 1) 993 FilterMode::NEAREST); 994 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 995 playbackCanvas_->DetachBrush(); 996 997 // 7.组合Clip函数ClipRoundRect(G2),cilp也有抗锯齿效果,默认和笔刷效果保持一致 998 TestBase::ClipRoundRectG2(true); 999 } 1000 1001 // Pixmap_Scene_0168 1002 // Pixmap构造接口:Pixmap_ImageInfo_13 1003 // Pixmap操作接口:GetAddr 1004 // cilp:ClipPath 1005 // transform:Scale(极小值) 1006 // 抗锯齿:AA 1007 // 透明度:透明 1008 // 视效:CreateSrgbGammaToLinear 1009 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 18) 1010 { 1011 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 1012 Drawing::Brush brush; 1013 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 1014 1015 // 2.Pixmap构造接口,Pixmap_ImageInfo_13 1016 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 1017 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_BGRA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 1018 colorspace); // 512 width * 512 height 1019 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 1020 1021 // 3.Pixmap操作接口GetAddr,绘制部分放到第6步的绘制结果里 1022 1023 Drawing::Bitmap bitmap1; 1024 bitmap1.Build(imageInfo); 1025 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 1026 bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色 1027 1028 // 4.设置视效效果CreateSrgbGammaToLinear,将效果添加到笔刷 1029 brush.SetColor(0xFF4F7091); 1030 auto filter = Drawing::Filter(); 1031 filter.SetColorFilter(Drawing::ColorFilter::CreateSrgbGammaToLinear()); 1032 brush.SetFilter(filter); 1033 1034 // 5.组合transform函数Scale(极小值) 1035 playbackCanvas_->Scale(10100.0f, 1.0f); // ratio 1036 1037 // 6.绘制结果 1038 const void* pixel = pixmap.GetAddr(); 1039 bitmap1.SetPixels(const_cast<void*>(pixel)); 1040 playbackCanvas_->AttachBrush(brush); 1041 playbackCanvas_->DrawBitmap(bitmap1, 300, 300); // 300,300 is bitmap1 position 1042 playbackCanvas_->DetachBrush(); 1043 1044 // 7.组合Clip函数ClipPath,cilp也有抗锯齿效果,默认和笔刷效果保持一致 1045 TestBase::ClipPath(true); 1046 } 1047 1048 // Pixmap_Scene_0169 1049 // Pixmap构造接口:Pixmap_ImageInfo_13 1050 // Pixmap操作接口:GetAddr 1051 // cilp:ClipRoundRect(G2_capsule) 1052 // transform:Scale(极大值) 1053 // 抗锯齿:非AA 1054 // 透明度:透明 1055 // 视效:CreateLinearToSrgbGamma 1056 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 19) 1057 { 1058 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:非AA 1059 Drawing::Brush brush; 1060 brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 1061 1062 // 2.Pixmap构造接口,Pixmap_ImageInfo_13 1063 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 1064 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_BGRA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 1065 colorspace); // 512 width * 512 height 1066 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 1067 1068 // 3.Pixmap操作接口GetAddr,绘制部分放到第6步的绘制结果里 1069 1070 Drawing::Bitmap bitmap1; 1071 bitmap1.Build(imageInfo); 1072 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 1073 bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色 1074 1075 // 4.设置视效效果CreateLinearToSrgbGamma,将效果添加到笔刷 1076 brush.SetColor(0xFF4F7091); 1077 auto filter = Drawing::Filter(); 1078 filter.SetColorFilter(Drawing::ColorFilter::CreateLinearToSrgbGamma()); 1079 brush.SetFilter(filter); 1080 1081 // 5.组合transform函数Scale(极大值) 1082 playbackCanvas_->Scale(1.0f, 10100.0f); // ratio 1083 1084 // 6.绘制结果 1085 const void* pixel = pixmap.GetAddr(); 1086 bitmap1.SetPixels(const_cast<void*>(pixel)); 1087 playbackCanvas_->AttachBrush(brush); 1088 playbackCanvas_->DrawBitmap(bitmap1, 300, 300); // 300,300 is bitmap1 position 1089 playbackCanvas_->DetachBrush(); 1090 1091 // 7.组合Clip函数ClipRoundRect(G2_capsule),cilp也有抗锯齿效果,默认和笔刷效果保持一致 1092 TestBase::ClipRoundRectG2capsule(false); 1093 } 1094 1095 // Pixmap_Scene_0170 1096 // Pixmap构造接口:Pixmap_ImageInfo_13 1097 // Pixmap操作接口:GetColor 1098 // cilp:ClipRect 1099 // transform:Translate 1100 // 抗锯齿:非AA 1101 // 透明度:半透明 1102 // 视效:CreateComposeColorFilter 1103 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 20) 1104 { 1105 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:非AA 1106 Drawing::Brush brush; 1107 brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 1108 1109 // 2.Pixmap构造接口,Pixmap_ImageInfo_13 1110 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 1111 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_BGRA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 1112 colorspace); // 512 width * 512 height 1113 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 1114 1115 // 3.Pixmap操作接口GetColor,绘制部分放到第6步的绘制结果里 1116 Drawing::Pen pen; 1117 pen.SetWidth(8.5f); 1118 pen.SetColor(pixmap.GetColor(imageInfo.GetWidth() / 2, imageInfo.GetHeight() / 2)); 1119 1120 Drawing::Bitmap bitmap1; 1121 bitmap1.Build(imageInfo); 1122 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 1123 bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色 1124 1125 // 4.设置视效效果CreateComposeColorFilter,将效果添加到笔刷 1126 brush.SetColor(0xFFFF0000); 1127 std::shared_ptr<Drawing::ColorFilter> colorFilter1 = 1128 Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF0000, Drawing::BlendMode::SRC_IN); 1129 std::shared_ptr<Drawing::ColorFilter> colorFilter2 = 1130 Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF00FF, Drawing::BlendMode::MODULATE); 1131 std::shared_ptr<Drawing::ColorFilter> colorFilter3 = 1132 Drawing::ColorFilter::CreateComposeColorFilter(*colorFilter1, *colorFilter2); 1133 auto filter = Drawing::Filter(); 1134 filter.SetColorFilter(colorFilter3); 1135 brush.SetFilter(filter); 1136 1137 // 5.组合transform函数Translate 1138 playbackCanvas_->Translate(200, 200); // 200 distance 1139 1140 // 6.绘制结果 1141 const void* pixel = pixmap.GetAddr(); 1142 bitmap1.SetPixels(const_cast<void*>(pixel)); 1143 playbackCanvas_->AttachBrush(brush); 1144 playbackCanvas_->AttachPen(pen); 1145 auto p1 = Drawing::Point(800, 800); // point position(800, 800) 1146 auto p2 = Drawing::Point(1000, 1000); // point position(1000, 1000) 1147 playbackCanvas_->DrawLine(p1, p2); 1148 playbackCanvas_->DetachPen(); 1149 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 1150 playbackCanvas_->DetachBrush(); 1151 1152 // 7.组合Clip函数ClipRect,cilp也有抗锯齿效果,默认和笔刷效果保持一致 1153 TestBase::ClipRect(false); 1154 } 1155 1156 // Pixmap_Scene_0171 1157 // Pixmap构造接口:Pixmap_ImageInfo_13 1158 // Pixmap操作接口:GetColor 1159 // cilp:ClipRoundRect(非G2) 1160 // transform:Scale(极小值) 1161 // 抗锯齿:AA 1162 // 透明度:半透明 1163 // 视效:null 1164 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 21) 1165 { 1166 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 1167 Drawing::Brush brush; 1168 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 1169 1170 // 2.Pixmap构造接口,Pixmap_ImageInfo_13 1171 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 1172 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_BGRA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 1173 colorspace); // 512 width * 512 height 1174 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 1175 1176 // 3.Pixmap操作接口GetColor,绘制部分放到第6步的绘制结果里 1177 Drawing::Pen pen; 1178 pen.SetWidth(8.5f); 1179 pen.SetColor(pixmap.GetColor(imageInfo.GetWidth() / 2, imageInfo.GetHeight() / 2)); 1180 1181 Drawing::Bitmap bitmap1; 1182 bitmap1.Build(imageInfo); 1183 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 1184 bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色 1185 1186 // 4.无视效效果函数 1187 // 5.组合transform函数Scale(极小值) 1188 playbackCanvas_->Scale(10100.0f, 1.0f); // ratio 1189 1190 // 6.绘制结果 1191 const void* pixel = pixmap.GetAddr(); 1192 bitmap1.SetPixels(const_cast<void*>(pixel)); 1193 playbackCanvas_->AttachBrush(brush); 1194 playbackCanvas_->AttachPen(pen); 1195 auto p1 = Drawing::Point(800, 800); // point position(800, 800) 1196 auto p2 = Drawing::Point(1000, 1000); // point position(1000, 1000) 1197 playbackCanvas_->DrawLine(p1, p2); 1198 playbackCanvas_->DetachPen(); 1199 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 1200 playbackCanvas_->DetachBrush(); 1201 1202 // 7.组合Clip函数ClipRoundRect(非G2),cilp也有抗锯齿效果,默认和笔刷效果保持一致 1203 TestBase::ClipRoundRectnotG2(true); 1204 } 1205 1206 // Pixmap_Scene_0172 1207 // Pixmap构造接口:Pixmap_ImageInfo_13 1208 // Pixmap操作接口:ScalePixels 1209 // cilp:ClipRoundRect(G2) 1210 // transform:Scale(极大值) 1211 // 抗锯齿:AA 1212 // 透明度:不透明 1213 // 视效:CreateColorShader 1214 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 22) 1215 { 1216 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 1217 Drawing::Brush brush; 1218 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 1219 1220 // 2.Pixmap构造接口,Pixmap_ImageInfo_13 1221 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 1222 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_BGRA_8888, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 1223 colorspace); // 512 width * 512 height 1224 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 1225 1226 // 3.Pixmap操作接口ScalePixels,绘制部分放到第6步的绘制结果里 1227 ImageInfo imageinfo2 = ImageInfo::MakeN32Premul(4, 4); // pixel row and col(4, 4) 1228 uint32_t data[16]; 1229 Pixmap dst(imageinfo2, data, sizeof(uint32_t) * imageinfo2.GetWidth()); 1230 1231 Drawing::Bitmap bitmap1; 1232 bitmap1.Build(imageInfo); 1233 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 1234 bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色 1235 1236 // 4.设置视效效果CreateColorShader,将效果添加到笔刷 1237 brush.SetColor(0xFFFF0000); 1238 auto colorShader = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_RED); 1239 brush.SetShaderEffect(colorShader); 1240 1241 // 5.组合transform函数Scale(极大值) 1242 playbackCanvas_->Scale(1.0f, 10100.0f); // ratio 1243 1244 // 6.绘制结果 1245 const void* pixel = pixmap.GetAddr(); 1246 bitmap1.SetPixels(const_cast<void*>(pixel)); 1247 playbackCanvas_->AttachBrush(brush); 1248 if (pixmap.ScalePixels(dst, SamplingOptions())) { 1249 playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000) 1250 } else { 1251 playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200) 1252 } 1253 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 1254 playbackCanvas_->DetachBrush(); 1255 1256 // 7.组合Clip函数ClipRoundRect(G2),cilp也有抗锯齿效果,默认和笔刷效果保持一致 1257 TestBase::ClipRoundRectG2(true); 1258 } 1259 1260 // Pixmap_Scene_0173 1261 // Pixmap构造接口:Pixmap_ImageInfo_14 1262 // Pixmap操作接口:GetWidth 1263 // cilp:ClipPath 1264 // transform:Shear 1265 // 抗锯齿:AA 1266 // 透明度:透明 1267 // 视效:CreateLumaColorFilter 1268 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 23) 1269 { 1270 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 1271 Drawing::Brush brush; 1272 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 1273 1274 // 2.Pixmap构造接口,Pixmap_ImageInfo_14 1275 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 1276 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_F16, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 1277 colorspace); // 512 width * 512 height 1278 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 1279 1280 // 3.Pixmap操作接口GetWidth,绘制部分放到第6步的绘制结果里 1281 auto width = pixmap.GetWidth(); 1282 1283 Drawing::Bitmap bitmap1; 1284 bitmap1.Build(imageInfo); 1285 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 1286 bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色 1287 1288 // 4.设置视效效果CreateLumaColorFilter,将效果添加到笔刷 1289 brush.SetColor(0xFF0000FF); 1290 auto filter = Drawing::Filter(); 1291 filter.SetColorFilter(Drawing::ColorFilter::CreateLumaColorFilter()); 1292 brush.SetFilter(filter); 1293 1294 // 5.组合transform函数Shear 1295 playbackCanvas_->Shear(10.0f, 10.0f); // slope 1296 1297 // 6.绘制结果 1298 const void* pixel = pixmap.GetAddr(); 1299 bitmap1.SetPixels(const_cast<void*>(pixel)); 1300 playbackCanvas_->AttachBrush(brush); 1301 playbackCanvas_->DrawRect(Rect(0, 0, width, 500)); // width * 500 height 1302 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 1303 playbackCanvas_->DetachBrush(); 1304 1305 // 7.组合Clip函数ClipPath,cilp也有抗锯齿效果,默认和笔刷效果保持一致 1306 TestBase::ClipPath(true); 1307 } 1308 1309 // Pixmap_Scene_0174 1310 // Pixmap构造接口:Pixmap_ImageInfo_14 1311 // Pixmap操作接口:GetWidth 1312 // cilp:null 1313 // transform:null 1314 // 抗锯齿:非AA 1315 // 透明度:不透明 1316 // 视效:CreateBlurImageFilter 1317 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 24) 1318 { 1319 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:非AA 1320 Drawing::Brush brush; 1321 brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 1322 1323 // 2.Pixmap构造接口,Pixmap_ImageInfo_14 1324 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 1325 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_F16, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 1326 colorspace); // 512 width * 512 height 1327 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 1328 1329 // 3.Pixmap操作接口GetWidth,绘制部分放到第6步的绘制结果里 1330 auto width = pixmap.GetWidth(); 1331 1332 Drawing::Bitmap bitmap1; 1333 bitmap1.Build(imageInfo); 1334 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 1335 bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色 1336 1337 // 4.设置视效效果CreateBlurImageFilter,将效果添加到笔刷 1338 brush.SetColor(0xFFFF0000); 1339 auto filter = Drawing::Filter(); 1340 filter.SetImageFilter(Drawing::ImageFilter::CreateBlurImageFilter( 1341 10.0f, 10.0f, Drawing::TileMode::CLAMP, nullptr, Drawing::ImageBlurType::GAUSS)); 1342 brush.SetFilter(filter); 1343 1344 // 5.无transform函数 1345 // 6.绘制结果 1346 const void* pixel = pixmap.GetAddr(); 1347 bitmap1.SetPixels(const_cast<void*>(pixel)); 1348 playbackCanvas_->AttachBrush(brush); 1349 playbackCanvas_->DrawRect(Rect(0, 0, width, 500)); // width * 500 height 1350 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 1351 playbackCanvas_->DetachBrush(); 1352 1353 // 7.无Clip函数 1354 } 1355 1356 // Pixmap_Scene_0175 1357 // Pixmap构造接口:Pixmap_ImageInfo_14 1358 // Pixmap操作接口:GetHeight 1359 // cilp:ClipPath 1360 // transform:ConcatMatrix 1361 // 抗锯齿:AA 1362 // 透明度:透明 1363 // 视效:CreateBlendModeColorFilter 1364 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 25) 1365 { 1366 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 1367 Drawing::Brush brush; 1368 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 1369 1370 // 2.Pixmap构造接口,Pixmap_ImageInfo_14 1371 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 1372 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_F16, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 1373 colorspace); // 512 width * 512 height 1374 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 1375 1376 // 3.Pixmap操作接口GetHeight,绘制部分放到第6步的绘制结果里 1377 auto height = pixmap.GetHeight(); 1378 1379 Drawing::Bitmap bitmap1; 1380 bitmap1.Build(imageInfo); 1381 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 1382 bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色 1383 1384 // 4.组合transform函数ConcatMatrix 1385 Drawing::Matrix matrix; 1386 matrix.Rotate(15, 10, 10); // 15 angle 10 position 1387 playbackCanvas_->ConcatMatrix(matrix); 1388 1389 brush.SetColor(0xFFFF0000); 1390 int rectPos = 0; 1391 for (auto blendMode : blendModes) { 1392 std::shared_ptr<Drawing::ColorFilter> colorFilter = 1393 Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF0000, blendMode); 1394 auto filter = Drawing::Filter(); 1395 // 5.设置视效效果CreateBlendModeColorFilter,将效果添加到笔刷 1396 filter.SetColorFilter(colorFilter); 1397 brush.SetFilter(filter); 1398 // 6.绘制结果 1399 const void* pixel = pixmap.GetAddr(); 1400 bitmap1.SetPixels(const_cast<void*>(pixel)); 1401 playbackCanvas_->AttachBrush(brush); 1402 playbackCanvas_->DrawRect(Rect(0 + (rectPos % VARIATION) * LEFT, 0 + (rectPos / VARIATION) * LEFT, 1403 500 + (rectPos % VARIATION) * LEFT, height + (rectPos / VARIATION) * LEFT)); // 500 width * height 1404 playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT, 1405 300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap position 1406 rectPos += 1; 1407 } 1408 playbackCanvas_->DetachBrush(); 1409 1410 // 7.组合Clip函数ClipPath,cilp也有抗锯齿效果,默认和笔刷效果保持一致 1411 TestBase::ClipPath(true); 1412 } 1413 1414 // Pixmap_Scene_0176 1415 // Pixmap构造接口:Pixmap_ImageInfo_14 1416 // Pixmap操作接口:GetHeight 1417 // cilp:ClipRect 1418 // transform:null 1419 // 抗锯齿:非AA 1420 // 透明度:半透明 1421 // 视效:CreateBlendImageFilter 1422 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 26) 1423 { 1424 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:非AA 1425 Drawing::Brush brush; 1426 brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 1427 1428 // 2.Pixmap构造接口,Pixmap_ImageInfo_14 1429 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 1430 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_F16, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 1431 colorspace); // 512 width * 512 height 1432 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 1433 1434 // 3.Pixmap操作接口GetHeight,绘制部分放到第6步的绘制结果里 1435 auto height = pixmap.GetHeight(); 1436 1437 Drawing::Bitmap bitmap1; 1438 bitmap1.Build(imageInfo); 1439 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 1440 bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色 1441 1442 // 4.无transform函数 1443 1444 brush.SetColor(0x4CB21933); 1445 int rectPos = 0; 1446 for (auto blendMode : blendModes) { 1447 auto background = Drawing::ImageFilter::CreateBlurImageFilter( 1448 1.0f, 1.0f, Drawing::TileMode::REPEAT, nullptr, Drawing::ImageBlurType::GAUSS); 1449 auto foreground = Drawing::ImageFilter::CreateBlurImageFilter( 1450 1.0f, 1.0f, Drawing::TileMode::REPEAT, nullptr, Drawing::ImageBlurType::GAUSS); 1451 auto filter = Drawing::Filter(); 1452 // 5.设置视效效果CreateBlendImageFilter,将效果添加到笔刷 1453 filter.SetImageFilter(Drawing::ImageFilter::CreateBlendImageFilter(blendMode, background, foreground)); 1454 brush.SetFilter(filter); 1455 1456 // 6.绘制结果 1457 const void* pixel = pixmap.GetAddr(); 1458 bitmap1.SetPixels(const_cast<void*>(pixel)); 1459 playbackCanvas_->Save(); 1460 playbackCanvas_->AttachBrush(brush); 1461 playbackCanvas_->DrawRect(Rect(0 + (rectPos % VARIATION) * LEFT, 0 + (rectPos / VARIATION) * LEFT, 1462 500 + (rectPos % VARIATION) * LEFT, height + (rectPos / VARIATION) * LEFT)); // 500 width * height 1463 playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT, 1464 300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap position 1465 playbackCanvas_->Restore(); 1466 rectPos += 1; 1467 } 1468 playbackCanvas_->DetachBrush(); 1469 1470 // 7.组合Clip函数ClipRect,cilp也有抗锯齿效果,默认和笔刷效果保持一致 1471 TestBase::ClipRect(false); 1472 } 1473 1474 // Pixmap_Scene_0177 1475 // Pixmap构造接口:Pixmap_ImageInfo_14 1476 // Pixmap操作接口:GetColorType 1477 // cilp:ClipRect 1478 // transform:Rotate 1479 // 抗锯齿:非AA 1480 // 透明度:半透明 1481 // 视效:CreateComposeColorFilter 1482 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 27) 1483 { 1484 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:非AA 1485 Drawing::Brush brush; 1486 brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 1487 1488 // 2.Pixmap构造接口,Pixmap_ImageInfo_14 1489 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 1490 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_F16, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 1491 colorspace); // 512 width * 512 height 1492 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 1493 1494 // 3.Pixmap操作接口GetColorType,绘制部分放到第6步的绘制结果里 1495 1496 Drawing::Bitmap bitmap1; 1497 bitmap1.Build(imageInfo); 1498 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 1499 bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色 1500 1501 // 4.设置视效效果CreateComposeColorFilter,将效果添加到笔刷 1502 brush.SetColor(0xFFFF0000); 1503 std::shared_ptr<Drawing::ColorFilter> colorFilter1 = 1504 Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF0000, Drawing::BlendMode::SRC_IN); 1505 std::shared_ptr<Drawing::ColorFilter> colorFilter2 = 1506 Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF00FF, Drawing::BlendMode::MODULATE); 1507 std::shared_ptr<Drawing::ColorFilter> colorFilter3 = 1508 Drawing::ColorFilter::CreateComposeColorFilter(*colorFilter1, *colorFilter2); 1509 auto filter = Drawing::Filter(); 1510 filter.SetColorFilter(colorFilter3); 1511 brush.SetFilter(filter); 1512 1513 // 5.组合transform函数Rotate 1514 playbackCanvas_->Rotate(30, 10, 10); // 30 angle 10 position 1515 1516 // 6.绘制结果 1517 const void* pixel = pixmap.GetAddr(); 1518 bitmap1.SetPixels(const_cast<void*>(pixel)); 1519 playbackCanvas_->AttachBrush(brush); 1520 if (pixmap.GetColorType() == Drawing::ColorType::COLORTYPE_RGBA_F16) { 1521 playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000) 1522 } else { 1523 playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200) 1524 } 1525 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 1526 playbackCanvas_->DetachBrush(); 1527 1528 // 7.组合Clip函数ClipRect,cilp也有抗锯齿效果,默认和笔刷效果保持一致 1529 TestBase::ClipRect(false); 1530 } 1531 1532 // Pixmap_Scene_0178 1533 // Pixmap构造接口:Pixmap_ImageInfo_14 1534 // Pixmap操作接口:GetColorType 1535 // cilp:ClipRoundRect(G2) 1536 // transform:ConcatMatrix 1537 // 抗锯齿:AA 1538 // 透明度:不透明 1539 // 视效:null 1540 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 28) 1541 { 1542 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 1543 Drawing::Brush brush; 1544 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 1545 1546 // 2.Pixmap构造接口,Pixmap_ImageInfo_14 1547 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 1548 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_F16, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 1549 colorspace); // 512 width * 512 height 1550 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 1551 1552 // 3.Pixmap操作接口GetColorType,绘制部分放到第6步的绘制结果里 1553 1554 Drawing::Bitmap bitmap1; 1555 bitmap1.Build(imageInfo); 1556 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 1557 bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色 1558 1559 // 4.无视效效果函数 1560 1561 // 5.组合transform函数ConcatMatrix 1562 Drawing::Matrix matrix; 1563 matrix.Rotate(15, 10, 10); // 15 angle 10 position 1564 playbackCanvas_->ConcatMatrix(matrix); 1565 1566 // 6.绘制结果 1567 const void* pixel = pixmap.GetAddr(); 1568 bitmap1.SetPixels(const_cast<void*>(pixel)); 1569 playbackCanvas_->AttachBrush(brush); 1570 if (pixmap.GetColorType() == Drawing::ColorType::COLORTYPE_RGBA_F16) { 1571 playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000) 1572 } else { 1573 playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200) 1574 } 1575 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 1576 playbackCanvas_->DetachBrush(); 1577 1578 // 7.组合Clip函数ClipRoundRect(G2),cilp也有抗锯齿效果,默认和笔刷效果保持一致 1579 TestBase::ClipRoundRectG2(true); 1580 } 1581 1582 // Pixmap_Scene_0179 1583 // Pixmap构造接口:Pixmap_ImageInfo_14 1584 // Pixmap操作接口:GetAlphaType 1585 // cilp:ClipRoundRect(G2) 1586 // transform:Scale(正常值) 1587 // 抗锯齿:AA 1588 // 透明度:透明 1589 // 视效:CreateMatrixColorFilter 1590 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 29) 1591 { 1592 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:AA 1593 Drawing::Brush brush; 1594 brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 1595 1596 // 2.Pixmap构造接口,Pixmap_ImageInfo_14 1597 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 1598 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_F16, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 1599 colorspace); // 512 width * 512 height 1600 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 1601 1602 // 3.Pixmap操作接口GetAlphaType,绘制部分放到第6步的绘制结果里 1603 1604 Drawing::Bitmap bitmap1; 1605 bitmap1.Build(imageInfo); 1606 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 1607 bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色 1608 1609 // 4.设置视效效果CreateMatrixColorFilter,将效果添加到笔刷 1610 Drawing::ColorMatrix matrix; 1611 matrix.SetArray(ARR); 1612 auto cf = Drawing::ColorFilter::CreateMatrixColorFilter(matrix); 1613 auto filter = Drawing::Filter(); 1614 filter.SetImageFilter(Drawing::ImageFilter::CreateColorFilterImageFilter(*cf, nullptr)); 1615 brush.SetFilter(filter); 1616 1617 // 5.组合transform函数Scale(正常值) 1618 playbackCanvas_->Scale(2.0f, 2.0f); // ratio 1619 1620 // 6.绘制结果 1621 const void* pixel = pixmap.GetAddr(); 1622 bitmap1.SetPixels(const_cast<void*>(pixel)); 1623 playbackCanvas_->AttachBrush(brush); 1624 if (pixmap.GetAlphaType() == Drawing::AlphaType::ALPHATYPE_UNKNOWN) { 1625 playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000) 1626 } else { 1627 playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200) 1628 } 1629 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 1630 playbackCanvas_->DetachBrush(); 1631 1632 // 7.组合Clip函数ClipRoundRect(G2),cilp也有抗锯齿效果,默认和笔刷效果保持一致 1633 TestBase::ClipRoundRectG2(true); 1634 } 1635 1636 // Pixmap_Scene_0180 1637 // Pixmap构造接口:Pixmap_ImageInfo_14 1638 // Pixmap操作接口:GetColorSpace 1639 // cilp:ClipRoundRect(G2_capsule) 1640 // transform:Scale(极大值) 1641 // 抗锯齿:非AA 1642 // 透明度:半透明 1643 // 视效:CreateSrgbGammaToLinear 1644 DEF_DTK(DTK_Pixmap_Scene6, TestLevel::L2, 30) 1645 { 1646 // 1.创建笔刷,设置笔刷是否为抗锯齿效果,抗锯齿:非AA 1647 Drawing::Brush brush; 1648 brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿) 1649 1650 // 2.Pixmap构造接口,Pixmap_ImageInfo_14 1651 auto colorspace = Drawing::ColorSpace::CreateSRGB(); 1652 ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_RGBA_F16, Drawing::AlphaType::ALPHATYPE_UNKNOWN, 1653 colorspace); // 512 width * 512 height 1654 Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth()); 1655 1656 // 3.Pixmap操作接口GetColorSpace,绘制部分放到第6步的绘制结果里 1657 1658 Drawing::Bitmap bitmap1; 1659 bitmap1.Build(imageInfo); 1660 // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明 1661 bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色 1662 1663 // 4.设置视效效果CreateSrgbGammaToLinear,将效果添加到笔刷 1664 brush.SetColor(0xFF4F7091); 1665 auto filter = Drawing::Filter(); 1666 filter.SetColorFilter(Drawing::ColorFilter::CreateSrgbGammaToLinear()); 1667 brush.SetFilter(filter); 1668 1669 // 5.组合transform函数Scale(极大值) 1670 playbackCanvas_->Scale(1.0f, 10100.0f); // ratio 1671 1672 // 6.绘制结果 1673 const void* pixel = pixmap.GetAddr(); 1674 bitmap1.SetPixels(const_cast<void*>(pixel)); 1675 playbackCanvas_->AttachBrush(brush); 1676 if (pixmap.GetColorSpace() == colorspace) { 1677 playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000) 1678 } else { 1679 playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200) 1680 } 1681 playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap position 1682 playbackCanvas_->DetachBrush(); 1683 1684 // 7.组合Clip函数ClipRoundRect(G2_capsule),cilp也有抗锯齿效果,默认和笔刷效果保持一致 1685 TestBase::ClipRoundRectG2capsule(false); 1686 } 1687 1688 } // namespace Rosen 1689 } // namespace OHOS