The vtkJPEGWriter failed to save the image

Hi all,
I want to save the window rendering results to image,but when i do so by using “vtkRenderLargeImage” and "vtkJPEGWriter " I get error message like below.

Can someone help?

very thanks!!!

code:

    vtkNew<vtkRenderLargeImage> renderLarge;
    renderLarge->SetInput(renderer);
    renderLarge->SetMagnification(1);
    renderLarge->Update();

    vtkNew<vtkJPEGWriter> writer;
    writer->SetFileName("screenshot.jpg");
    writer->SetInputData(renderLarge->GetOutput());
    writer->SetQuality(100);
    writer->Write();

error message:

Generic Warning: In vtkOpenGLState.cxx, line 72
Error in cache state for GL_BLEND

Generic Warning: In vtkOpenGLState.cxx, line 79
Error in cache state for GL_DEPTH_TEST

Generic Warning: In vtkOpenGLState.cxx, line 102
Error in cache state for GL_SCISSOR_TEST

Generic Warning: In vtkOpenGLState.cxx, line 133
Error in cache state for GL_VIEWPORT

Generic Warning: In vtkOpenGLState.cxx, line 141
Error in cache state for GL_SCISSOR_BOX

Generic Warning: In vtkOpenGLState.cxx, line 155
Error in cache state for GL_ACTIVE_TEXTURE

Generic Warning: In vtkOpenGLState.cxx, line 162
Error in cache state for GL_DEPTH_FUNC

Generic Warning: In vtkOpenGLState.cxx, line 169
Error in cache state for GL_BLEND_SRC_RGB

Generic Warning: In vtkOpenGLState.cxx, line 197
Error in cache state for GL_DRAW_FRAMEBUFFER_BINDING

Generic Warning: In vtkOpenGLState.cxx, line 255
Error in cache state for GL_COLOR_CLEAR_VALUE

Generic Warning: In vtkOpenGLState.cxx, line 263
at stack loc
 at vtksys::RegularExpression::operator=
 at vtksys::RegularExpression::operator=
 at vtkOpenGLState::ResetGLActiveTexture
 at vtkOpenGLState::ResetGLActiveTexture
 at vtkOpenGLState::ResetGLActiveTexture
 at vtkOpenGLState::ResetGLActiveTexture
 at vtkRenderer::SetEnvironmentUp
 at vtkCameraPathRepresentation::UpdateConfiguration
 at vtkRenderer::SetEnvironmentUp
 at vtkRenderer::SetEnvironmentUp
 at vtkOpenGLState::ResetGLActiveTexture
 at vtkOpenGLState::ResetGLActiveTexture
 at vtkOpenGLState::ResetGLActiveTexture
 at vtkRenderer::SetEnvironmentUp
 at vtkRenderer::SetEnvironmentUp
 at vtkRenderer::SetEnvironmentUp
 at vtkRenderer::SetEnvironmentUp
 at vtkOpenGLState::ResetGLActiveTexture
 at vtkOpenGLState::ResetGLActiveTexture
 at vtkRenderer::SetEnvironmentUp
 at QQuickVTKRenderItem::addWidget
 at QQuickVTKRenderItem::addWidget
 at QQuickVTKRenderItem::addWidget
 at QQuickVTKRenderItem::addWidget
 at qIsFinite
 at qIsFinite
 at qIsFinite
 at QQuickItemPrivate::childContainerNode
 at QQuickItemPrivate::childContainerNode
 at QQuickItemPrivate::childContainerNode
 at QQuickItemPrivate::childContainerNode
 at qIsFinite
 at BaseThreadInitThunk
 at RtlUserThreadStart