Hi,
I am just trying to make a simple Skia program. A very simple program, but as I run this code, the output image file never writes anything. I am running this code on VS 2015 : Debug : x64 and included the skia.lib and OpenGL32.lib static libraries.
Can someone tell me why this simple example does not work?
#include "skiaIncludes.h"
void draw(SkCanvas* canvas) { SkPaint paint; paint.setColor(SK_ColorWHITE); canvas->drawPaint(paint);}
int main (){ try { FILE * pFile; char buffer[100];
pFile = fopen("myfile.png", "wb");
sk_sp<SkSurface> rasterSurface( SkSurface::MakeRasterN32Premul(300, 300)); SkCanvas* rasterCanvas = rasterSurface->getCanvas();
//rasterCanvas->save(); rasterCanvas->translate(SkIntToScalar(128), SkIntToScalar(128)); rasterCanvas->rotate(SkIntToScalar(45)); SkRect rect = SkRect::MakeXYWH(-90.5f, -90.5f, 181.0f, 181.0f); SkPaint paint; paint.setColor(SK_ColorBLUE); rasterCanvas->drawRect(rect, paint); //rasterCanvas->restore();
sk_sp<SkImage> img = rasterSurface->makeImageSnapshot(); sk_sp<SkData> png(img->encode(SkEncodedImageFormat::kPNG, 100)); rasterCanvas->drawImage(img, 0, 0); png->MakeFromFILE(pFile);
fclose(pFile); } catch (std::exception ex){ printf(ex.what()); }
return 0;}
header file
#pragma once
#include "core/SkData.h"#include "core/SkImage.h"#include "core/SkStream.h"#include "core/SkSurface.h"#include "core/SkCanvas.h"#include "core/SkGraphics.h"#include "core/SkImageEncoder.h"#include "gpu/gl/GrGLInterface.h"#include "gpu/gl/GrGLExtensions.h"#include <fstream>#include <sys/stat.h>#include <sys/types.h>#include <fcntl.h>#include <exception>#include <iostream>NextVR, Inc. technology is protected by US Patents 8,451,320, 8,610,757, 9,204,127, 9,313,474, 9,538,160, 9,485,494 and 9,407,902 with additional patents pending. The information contained in this transmission contains privileged and confidential information. It is intended only for the use of the person(s) named above. If you are not the intended recipient, you are hereby notified that any review, dissemination, distribution or duplication of this communication is strictly prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.--
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.
NextVR, Inc. technology is protected by US Patents 8,451,320, 8,610,757, 9,204,127, 9,313,474, 9,538,160, 9,485,494 and 9,407,902 with additional patents pending. The information contained in this transmission contains privileged and confidential information. It is intended only for the use of the person(s) named above. If you are not the intended recipient, you are hereby notified that any review, dissemination, distribution or duplication of this communication is strictly prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
--
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+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
I think you want to use an SkFILEWStream, found in SkStreams.h. Or just write the data in png yourself (using png->data() or png->bytes(), and png->size()).
--