어디서나 수색했으며 2 일 후에도 해결책을 찾을 수 없습니다.GraphicsView fitInView() 화면 축소시 매우 pixelated 결과
문제 :
나는 기능을 "보기 맞춤 이미지"로 이미지 뷰어를하고 있어요. 내 GraphicsView (당연히 훨씬 더 작음)에서 3000+ 픽셀이라고 말하는 그림을로드하면 스크롤바가 잘 보입니다. 난 내 btnFitView을 클릭하고 실행하면 :
ui->graphicsView->fitInView(scene->sceneRect(),Qt::KeepAspectRatio);
을이 바로 스케일링 다운? fitInView() 후에 모든 라인이 픽셀 화됩니다. 톱이 이미지의 선을 넘은 것처럼 보입니다.
예 : 자동차의 이미지에는 선이 있고, 문자 메시지의 이미지 (문자는 매우 나쁜 품질이됩니다).
내 코드 샘플 :
// select file, load image in view
QString strFilePath = QFileDialog::getOpenFileName(
this,
tr("Open File"),
"/home",
tr("Images (*.png *.jpg)"));
imageObject = new QImage();
imageObject->load(strFilePath);
image = QPixmap::fromImage(*imageObject);
scene = new QGraphicsScene(this);
scene->addPixmap(image);
scene->setSceneRect(image.rect());
ui->graphicsView->setScene(scene);
// on_btnFitView_Clicked() :
ui->graphicsView->fitInView(scene->sceneRect(),Qt::KeepAspectRatio);
직전 fitInView(), 크기는 다음과 같습니다
qDebug()<<"sceneRect = "<< scene->sceneRect();
qDebug()<<"viewRect = " << ui->graphicsView->rect();
sceneRect = QRectF(0,0 1000x750)
viewRect = QRect(0,0 733x415)
는 내가 원래로드 된 이미지의 스크린 샷을 업로드 할 수 있습니다 필요하며, 뷰에 장착하면?
내가이 일을 올바르게하고 있습니까? 자동 피팅을 위해 fitInView를 사용하여 웹의 모든 예제가 작동하는 것 같습니다. 아마도 pixmap에서 다른 작업을 사용해야할까요? downshrink에
솔루션
// LOAD IMAGE
bool ImgViewer::loadImage(const QString &strImagePath)
{
m_image = new QImage(strImagePath);
if(m_image->isNull()){
return false;
}
clearView();
m_pixmap = QPixmap::fromImage(*m_image);
m_pixmapItem = m_scene->addPixmap(m_pixmap);
m_scene->setSceneRect(m_pixmap.rect());
this->centerOn(m_pixmapItem);
// preserve fitView if active
if(m_IsFitInView)
fitView();
return true;
}
// TOGGLED FUNCTIONS
void ImgViewer::fitView()
{
if(m_image->isNull())
return;
this->resetTransform();
QPixmap px = m_pixmap; // use local pixmap (not original) otherwise image is blurred after scaling the same image multiple times
px = px.scaled(QSize(this->width(),this->height()),Qt::KeepAspectRatio,Qt::SmoothTransformation);
m_pixmapItem->setPixmap(px);
m_scene->setSceneRect(px.rect());
}
void ImgViewer::originalSize()
{
if(m_image->isNull())
return;
this->resetTransform();
m_pixmap = m_pixmap.scaled(QSize(m_image.width(),m_image.height()),Qt::KeepAspectRatio,Qt::SmoothTransformation);
m_pixmapItem->setPixmap(m_pixmap);
m_scene->setSceneRect(m_pixmap.rect());
this->centerOn(m_pixmapItem); //ensure item is centered in the view.
}
이 좋은 품질을 생산하고 있습니다. 문제가 fitView에 전화 한 후, 지금이
// "originalSize()" : IMAGE SIZE = (1152, 2048)
// "originalSize()" : PIXMAP SIZE = (1152, 2048)
// "originalSize()" : VIEW SIZE = (698, 499)
// "originalSize()" : SCENE SIZE = (1152, 2048)
// "fitView()" : IMAGE SIZE = (1152, 2048)
// "fitView()" : PIXMAP SIZE = (1152, 2048)
// "fitView()" : VIEW SIZE = (698, 499)
// "fitView()" : SCENE SIZE = (280, 499)
()가 장면의 크기를 보면 다음은이 두 함수를 호출 한 후 일부 통계는 무엇입니까? 더 작은.
그리고 fitView()가 활성화되어 있고 wheelEvent (zoomIn/zoomOut)에서 이미지를 축척하고 뷰 축척 기능을 사용합니다. scale (factor, factor); .. 끔찍한 결과를 낳는다. 장면 크기가 이미지 크기와 같은 originalSize()에서는 이러한 일이 발생하지 않습니다.
렌더링 힌트를 'ui-> graphicsView-> setRenderHints (QPainter :: Antialiasing | QPainter :: SmoothPixmapTransform);로 설정하면 더 좋아지고 있습니까? – tomvodi
렌더링 힌트가 이미 설정되었으므로 불행히도 – PathOfNeo