QImage
에 원하는 크기를 지정하십시오. SVG 렌더러는 전체 이미지에 맞게 확장됩니다.
#include <QApplication>
#include <QSvgRenderer>
#include <QPainter>
#include <QImage>
// In your .pro file:
// QT += svg
int main(int argc, char **argv)
{
// A QApplication instance is necessary if fonts are used in the SVG
QApplication app(argc, argv);
// Load your SVG
QSvgRenderer renderer(QString("./svg-logo-h.svg"));
// Prepare a QImage with desired characteritisc
QImage image(500, 200, QImage::Format_ARGB32);
image.fill(0xaaA08080); // partly transparent red-ish background
// Get QPainter that paints to the image
QPainter painter(&image);
renderer.render(&painter);
// Save, image format based on file extension
image.save("./svg-logo-h.png");
}
이렇게하면 전달 된 SVG 파일에서 500x200 PNG 이미지가 생성됩니다.
SVG logos 페이지에서 SVG 이미지 출력 예 : 픽스맵 1 비트의 깊이를 갖는 경우, 반환 된 이미지는 것
QImage QPixmap::toImage()
: 여기
출처
2011-12-18 12:49:52
Mat
와우 위에서 복사! 나는 그것을 시험했다;) 고마워, 매력처럼 작동한다;) – Franki
더 간단한 해결책을 위해 이것을 보라. @stackoverflow.com/questions/10079011/qpixmap-and-svg/36936216#answer-36936216 – Yash
@Yash : 그러나 여기서의 질문은 스케일링을 요구합니다. (위의 대답은 필요한 것보다 약간 복잡하지만 데 필요한 다른 것들을 데모합니다.) – Mat