Color inversion problem occurs when exporting images
yufeiran opened this issue · 1 comments
Thank you for developing this library! When our program uses your library, some pictures appear to be exported to pdf. When opening this file with CorelDraw, the picture has an inverted color problem.😂I try different version of pdf, all have this problem. I don't know how to sovle it.🤣Could this problem be caused by LibJpeg?
raw picture
happen inverted color problem in CorelDraw 2019:
I use this code and build with Visual Studio 2022,
#include <iostream>
#include<PDFWriter/PDFWriter.h>
#include<PDFWriter/PDFPage.h>
#include<PDFWriter/AbstractContentContext.h>
#include<PDFWriter/PageContentContext.h>
using namespace std;
int main()
{
PDFWriter pdfWriter;
string filePath = "helloPDF.pdf";
if (pdfWriter.StartPDF(filePath.c_str(), ePDFVersion13) != eSuccess)
{
throw std::runtime_error("pdf create failed!");
}
string imagePath = "image/1.jpg";
DoubleAndDoublePair jpgDimensions = pdfWriter.GetImageDimensions(imagePath);
PDFPage* page = new PDFPage();
page->SetMediaBox(PDFRectangle(0, 0, jpgDimensions.first, jpgDimensions.second));
PageContentContext* cxt = pdfWriter.StartPageContentContext(page);
cxt->DrawImage(10, 10, imagePath.c_str());
pdfWriter.EndPageContentContext(cxt);
pdfWriter.WritePageAndRelease(page);
pdfWriter.EndPDF();
string cmd = "start " + filePath;
system(cmd.c_str());
return 0;
}
Thanks a lot!
I created the PDF file (attaching). I don't have coral draw, but opened it in acrobat reader and in chrome and it looks fine in both.
This might be something to ask Coral Draw then.
for the more specific question: JPGs are native in PDFS. you can pretty much embed them as is, which is what this library does, so no libjpg is involved here. libjpeg is only involved when parsing streams that are DCT encoded (examples are...embedding of jpg images), which is a fairly rare usage (you will, for example, use it when extracting images from a PDF).