OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "../include/core/SkCanvas.h" | 8 #include "../include/core/SkCanvas.h" |
9 #include "../include/core/SkData.h" | 9 #include "../include/core/SkData.h" |
10 #include "../include/core/SkSurface.h" | 10 #include "../include/core/SkSurface.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 paint.setAntiAlias(true); | 73 paint.setAntiAlias(true); |
74 paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShad
er::kRepeat_TileMode)); | 74 paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShad
er::kRepeat_TileMode)); |
75 | 75 |
76 // Draw to the surface via its SkCanvas. | 76 // Draw to the surface via its SkCanvas. |
77 SkCanvas* canvas = surface->getCanvas(); // We don't manage this pointer's
lifetime. | 77 SkCanvas* canvas = surface->getCanvas(); // We don't manage this pointer's
lifetime. |
78 static const char* msg = "Hello world!"; | 78 static const char* msg = "Hello world!"; |
79 canvas->clear(SK_ColorWHITE); | 79 canvas->clear(SK_ColorWHITE); |
80 canvas->drawText(msg, strlen(msg), 90,120, paint); | 80 canvas->drawText(msg, strlen(msg), 90,120, paint); |
81 | 81 |
82 // Grab a snapshot of the surface as an immutable SkImage. | 82 // Grab a snapshot of the surface as an immutable SkImage. |
83 std::shared_ptr<SkImage> image = adopt(surface->newImageSnapshot()); | 83 sk_sp<SkImage> image = surface->makeImageSnapshot(); |
84 // Encode that image as a .png into a blob in memory. | 84 // Encode that image as a .png into a blob in memory. |
85 std::shared_ptr<SkData> png = adopt(image->encode(SkImageEncoder::kPNG_Type,
100)); | 85 std::shared_ptr<SkData> png = adopt(image->encode(SkImageEncoder::kPNG_Type,
100)); |
86 | 86 |
87 // This code is no longer Skia-specific. We just dump the .png to disk. An
y way works. | 87 // This code is no longer Skia-specific. We just dump the .png to disk. An
y way works. |
88 static const char* path = "example.png"; | 88 static const char* path = "example.png"; |
89 std::ofstream(path, std::ios::out | std::ios::binary) | 89 std::ofstream(path, std::ios::out | std::ios::binary) |
90 .write((const char*)png->data(), png->size()); | 90 .write((const char*)png->data(), png->size()); |
91 std::cout << "Wrote " << path << std::endl; | 91 std::cout << "Wrote " << path << std::endl; |
92 | 92 |
93 return 0; | 93 return 0; |
94 } | 94 } |
OLD | NEW |