简体   繁体   English

在QPainter :: end()之前调用QImage :: save()是否安全?

[英]Is it safe to call QImage::save() before QPainter::end()

In this code: 在此代码中:

QPainter painter(&image);

// do painting .......

painter.end(); // is this needed?
image.save(tempFileName);

do I need to close the QPainter before saving the QImage, in order to flush all changes, or can I save it before closing the QPainter object? 保存QImage之前需要关闭QPainter以便刷新所有更改,还是可以在关闭QPainter对象之前保存QPainter?

Yes, you should call painter.end() prior to calling image.save() . 是的,你应该叫painter.end()之前调用image.save() The behavior of painter.end() ultimately depends on the underlying paint engine used on whatever platform your program is running on. painter.end()的行为最终取决于在程序运行所在的任何平台上使用的基础绘制引擎。 You may be able to get away with calling image.save() before painter.end() on some platforms with some versions of Qt, but changing either your platform or your version of Qt could cause you problems later on. 某些使用某些 Qt版本的平台上,您可能可以在painter.end() image.save()之前先调用image.save() ,但是更改平台或Qt版本可能会在以后引起问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM