SkDynamicMemoryWStream svgStream;
std::unique_ptr<SkXMLWriter> xmlWriter(
new SkXMLStreamWriter(&svgStream));
SkRect bounds = SkRect::MakeIWH(2000, 2000);
std::unique_ptr<SkCanvas> svgCanvas = SkSVGCanvas::Make(bounds, &svgStream);
SkPaint strokePaint;
strokePaint.setStyle(SkPaint::kStroke_Style);
strokePaint.setColor(SK_ColorBLACK);
strokePaint.setAntiAlias(true);
strokePaint.setStrokeWidth(5);
static SkScalar x,y, x2,y2;
static double angle = M_PI/6;
for (int i = 0; i < 10000; i++)
{
x2+=5;
y = 400+sin(angle/2)*300;
angle += M_PI/6;
y2 = 400+sin(angle/2)*300;
svgCanvas->drawLine(x,y,x2,y2,strokePaint);
x = x2;
}
svgCanvas->save();
Hi,I have the following piece of code and want to do two things:1- how can I get the relative xml string from SkSVGCanvas ?
2- how can I dump SkSVGCanvas to a PNG buffer?
ThanksHossSkDynamicMemoryWStream svgStream;
std::unique_ptr<SkXMLWriter> xmlWriter(
new SkXMLStreamWriter(&svgStream));
SkRect bounds = SkRect::MakeIWH(2000, 2000);
std::unique_ptr<SkCanvas> svgCanvas = SkSVGCanvas::Make(bounds, &svgStream);
SkPaint strokePaint;
strokePaint.setStyle(SkPaint::kStroke_Style);
strokePaint.setColor(SK_ColorBLACK);
strokePaint.setAntiAlias(true);
strokePaint.setStrokeWidth(5);
static SkScalar x,y, x2,y2;
static double angle = M_PI/6;
for (int i = 0; i < 10000; i++)
{
x2+=5;
y = 400+sin(angle/2)*300;
angle += M_PI/6;
y2 = 400+sin(angle/2)*300;
svgCanvas->drawLine(x,y,x2,y2,strokePaint);
x = x2;
}svgCanvas->save();
--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.
sk_sp<SkData> data = svgStream.detachAsData();
fwrite(data->data(), data->size(), 1, stdout);- PNG output:
Do you want the result of rasterizing SVG (Skia -> SVG -> raster), or the result of rasterizing Skia draw commands (Skia -> raster)?
SkAssertResult(canvas->readPixels(bmp, 0, 0));
but let me not confuse you, i still want the PNG in a buffer as I would to embed it in my application which then in turn sends it to a browser.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-d...@googlegroups.com.
Thanks for the reply.- XML output:I tried the below code but still cant see a thing...sk_sp<SkData> data = svgStream.detachAsData();
fwrite(data->data(), data->size(), 1, stdout);
SkDynamicMemoryWStream svgStream;
SkRect bounds = SkRect::MakeIWH(2000, 2000);
auto svgCanvas = SkSVGCanvas::Make(bounds, &svgStream);
SkPaint strokePaint;strokePaint.setStyle(SkPaint::kStroke_Style);strokePaint.setColor(SK_ColorBLACK);strokePaint.setAntiAlias(true);strokePaint.setStrokeWidth(5);static SkScalar x,y, x2,y2;static double angle = M_PI/6;for (int i = 0; i < 10000; i++){x2+=5;y = 400+sin(angle/2)*300;angle += M_PI/6;y2 = 400+sin(angle/2)*300;svgCanvas->drawLine(x,y,x2,y2,strokePaint);x = x2;}
svgCanvas = nullptr; // force-flush to streamauto data = svgStream.detachAsData();
fwrite(data->data(), data->size(), 1, stdout);
Output:
- PNG output:Do you want the result of rasterizing SVG (Skia -> SVG -> raster), or the result of rasterizing Skia draw commands (Skia -> raster)?ideally, the latter one. but it'd be great if i can see both.there is also a function in skiaserve called Request::writeCanvasToPng but when i pass my canvas to it, i am hitting the assert within it..SkAssertResult(canvas->readPixels(bmp, 0, 0));
...auto rasterSurface = SkSurface::MakeRasterN32Premul(bounds.width(), bounds.height());
auto dispatchCanvas = sk_make_sp<SkNWayCanvas>();dispatchCanvas->addCanvas(rasterSurface->getCanvas());
dispatchCanvas->addCanvas(svgCanvas.get());
// now draw to dispatchCanvas instead of svgCanvas
dispatchCanvas->lineTo(...);
...
// grab the XML output as before...
// grab the raster result
auto rasterImage = rasterSurface->makeImageSnapshot();
auto pngData = rasterImage->encodeToData();
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.