I want to export a 2D chart (vtkChartXY
) as a high resolution bitmap image (JPG
or PNG
). I'm able to export an image at screen resolution:
But when I try to increase the resolution using vtkWindowToImageFilter::SetMagnification(10)
, I obtain the following distorted image:
The text is just fine, but there are undesired spacings between the line segments.
I used the following code to generate the graph:
// Construct a random 2D chart
vtkNew<vtkContextView> pView;
vtkNew<vtkChartXY> pChart;
vtkPlot *pPlot = pChart->AddPlot(vtkChart::LINE);
vtkNew<vtkTable> pTable;
vtkNew<vtkDoubleArray> pX, pY;
pX->SetName("x");
pY->SetName("y");
for (int i = 0; i < 100; ++i)
{
pX->InsertNextTuple1(i);
pY->InsertNextTuple1(std::rand());
}
pTable->AddColumn(pX.Get());
pTable->AddColumn(pY.Get());
pPlot->SetInputData(pTable.Get(), "x", "y");
pView->GetScene()->AddItem(pChart.Get());
And the following code to export the graph to JPEG
:
// Export the image to JPG
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(pView->GetRenderer());
renderWindow->SetSize(300, 300);
renderWindow->OffScreenRenderingOn();
renderWindow->Render();
vtkNew<vtkWindowToImageFilter> windowToImageFilter;
windowToImageFilter->SetInput(renderWindow.Get());
// windowToImageFilter->SetMagnification(10); // uncomment this line to obtain the distorted image
vtkNew<vtkJPEGWriter> writer;
writer->SetFileName("test.jpg");
writer->SetInputConnection(windowToImageFilter->GetOutputPort());
writer->Write();
If it matters, I'm using VTK 7.1 on Ubuntu 16.04.
Question: How can I export a vtkChartXY
as a high resolution image without distorting my graph, i.e. undesired spacings between the line segments?