There is no code examples that I have yet seen that will draw a simple bitmap from a 1-d array of pixels and their respective colors. Can some one please give me a simple example. Thanks :)
--
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 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.
You can also use a variant called SkImage::MakeFromRaster(pixmap, proc, ctx) if you want to avoid making a copy of the pixels. You can pass null for the last 2 parameters if you know the pixels will outlive the image object.
--
constexpr int SkiaWidth = 1920;
constexpr int SkiaHeight = 1080;
//OUTPUT GRAYSCALE VERION OF THE OUTPUT IMAGE
size_t ImageBufferGrayScaleSize = SkiaHeight * SkiaWidth;
uint32_t * ImageBufferGrayScale = new uint32_t[ImageBufferGrayScaleSize];
for (int i = 0; i < imageRows * imageCols; ++i)
{
ImageBufferGrayScale[i] = 0xFF0000A1;
}
FILE * pFile;
errno_t errFile;
try {
errFile = fopen_s(&pFile, "myfile.png", "wb+");
assert(pFile);
if (errFile == 0)
{
printf("The file 'myfile.png' was opened\n");
}
else
{
printf("The file 'myfile.png' was not opened\n");
}
}
catch ( std::exception ex ){
std::cout << ex.what() << std::endl;
}
SkPixmap pixmap(SkImageInfo::Make(SkiaWidth, SkiaHeight, kN32_SkColorType, kPremul_SkAlphaType), ImageBufferGrayScale, sizeof(uint32_t) * ImageBufferGrayScaleSize);
if (!rasterCanvas->peekPixels(&pixmap))
{
printf("peekPixels false\n");
}
SkBitmap bm;
bm.installPixels(pixmap);
rasterCanvas->drawBitmap(bm, 0, 0, nullptr);
//fwrite(png->data(), png->size(), 1, pFile);
sk_sp<SkImage> img = rasterSurface->makeImageSnapshot();
sk_sp<SkData> png(img->encode(SkEncodedImageFormat::kPNG, 100));
fwrite(png->data(), png->size(), 1, pFile);
fclose(pFile);
Now I am trying to output the image to a file on disk and it's always blank.
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.
FILE * pFile;
errno_t errFile;
try {
errFile = fopen_s(&pFile, "myfile.png", "wb+");
assert(pFile);
if (errFile == 0)
{
printf("The file 'myfile.png' was opened\n");
}
else
{
printf("The file 'myfile.png' was not opened\n");
}
}
catch ( std::exception ex ){
std::cout << ex.what() << std::endl;
}
SkPixmap pixmap(SkImageInfo::Make(SkiaWidth, SkiaHeight, kN32_SkColorType, kPremul_SkAlphaType), ImageBufferGrayScale, sizeof(uint32_t) * ImageBufferGrayScaleSize);
sk_sp<SkImage> img = SkImage::MakeRasterCopy(pixmap);
sk_sp<SkData> png(img->encode(SkEncodedImageFormat::kPNG, 100));
fwrite(png->data(), png->size(), 1, pFile);
fclose(pFile);To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.