Hi channel,
I want to get started on Skia programming. This is basically a HelloWorld implementation trying to save an image as a jpeg. This code was compiled fine, but broke at SkAssertResult(canvas.peekPixels(&pixmap));. peekPixels function is failing. What is the problem with the peekPixels usage?
#include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h"
#include "include/core/SkImage.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkData.h"
#include "include/core/SkStream.h"
#include "include/encode/SkPngEncoder.h"
#include "include/encode/SkJpegEncoder.h"
constexpr static int multiplier = 5;
int main() {
// Create a new Skia canvas.
SkCanvas canvas(33 * multiplier, 48 * multiplier);
canvas.drawColor(SK_ColorWHITE);
SkPaint paint;
paint.setColor(SK_ColorBLUE);
canvas.drawCircle(64, 64, 64, paint);
// Create a new SkBitmap to store the generated JPEG image.
// SkBitmap bitmap;
SkPixmap pixmap;
// SkAssertResult(bitmap.peekPixels(&pixmap));
SkAssertResult(canvas.peekPixels(&pixmap));
SkFILEWStream stream("test.jpg");
SkJpegEncoder::Options options;
options.fQuality = 90;
auto ret = SkJpegEncoder::Encode(&stream, pixmap, options);
if (ret) {
printf("success\n");
} else {
printf("fail\n");
}
return 0;
}