本文整理汇总了C++中sk_sp::asLegacyBitmap方法的典型用法代码示例。如果您正苦于以下问题:C++ sk_sp::asLegacyBitmap方法的具体用法?C++ sk_sp::asLegacyBitmap怎么用?C++ sk_sp::asLegacyBitmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sk_sp
的用法示例。
在下文中一共展示了sk_sp::asLegacyBitmap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
const DrawOptions options = GetDrawOptions();
if (options.source) {
sk_sp<SkData> data(SkData::NewFromFileName(options.source));
if (!data) {
perror(options.source);
return 1;
} else {
image = SkImage::MakeFromEncoded(std::move(data));
if (!image) {
perror("Unable to decode the source image.");
return 1;
}
SkAssertResult(image->asLegacyBitmap(
&source, SkImage::kRO_LegacyBitmapMode));
}
}
sk_sp<SkData> rasterData, gpuData, pdfData, skpData;
if (options.raster) {
auto rasterSurface =
SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(options.size));
srand(0);
draw(rasterSurface->getCanvas());
rasterData.reset(encode_snapshot(rasterSurface));
}
if (options.gpu) {
auto grContext = create_grcontext();
if (!grContext) {
fputs("Unable to get GrContext.\n", stderr);
} else {
auto surface = SkSurface::MakeRenderTarget(
grContext.get(),
SkBudgeted::kNo,
SkImageInfo::MakeN32Premul(options.size));
if (!surface) {
fputs("Unable to get render surface.\n", stderr);
exit(1);
}
srand(0);
draw(surface->getCanvas());
gpuData.reset(encode_snapshot(surface));
}
}
if (options.pdf) {
SkDynamicMemoryWStream pdfStream;
sk_sp<SkDocument> document(SkDocument::MakePDF(&pdfStream));
srand(0);
draw(document->beginPage(options.size.width(), options.size.height()));
document->close();
pdfData.reset(pdfStream.copyToData());
}
if (options.skp) {
SkSize size;
size = options.size;
SkPictureRecorder recorder;
srand(0);
draw(recorder.beginRecording(size.width(), size.height()));
auto picture = recorder.finishRecordingAsPicture();
SkDynamicMemoryWStream skpStream;
picture->serialize(&skpStream);
skpData.reset(skpStream.copyToData());
}
printf("{\n");
dump_output(rasterData, "Raster", !gpuData && !pdfData && !skpData);
dump_output(gpuData, "Gpu", !pdfData && !skpData);
dump_output(pdfData, "Pdf", !skpData);
dump_output(skpData, "Skp");
printf("}\n");
return 0;
}