图像等比例缩放
This commit is contained in:
28
HPPA/AspectRatioLabel.cpp
Normal file
28
HPPA/AspectRatioLabel.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "stdafx.h"
|
||||||
|
#include "AspectRatioLabel.h"
|
||||||
|
|
||||||
|
AspectRatioLabel::AspectRatioLabel(QWidget* parent)
|
||||||
|
: QLabel(parent)
|
||||||
|
{
|
||||||
|
setAlignment(Qt::AlignCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AspectRatioLabel::setOriginalPixmap(const QPixmap& pixmap)
|
||||||
|
{
|
||||||
|
m_originalPixmap = pixmap;
|
||||||
|
updateScaledPixmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AspectRatioLabel::resizeEvent(QResizeEvent* event)
|
||||||
|
{
|
||||||
|
QLabel::resizeEvent(event);
|
||||||
|
updateScaledPixmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AspectRatioLabel::updateScaledPixmap()
|
||||||
|
{
|
||||||
|
if (m_originalPixmap.isNull())
|
||||||
|
return;
|
||||||
|
|
||||||
|
setPixmap(m_originalPixmap.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
|
}
|
||||||
22
HPPA/AspectRatioLabel.h
Normal file
22
HPPA/AspectRatioLabel.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QResizeEvent>
|
||||||
|
|
||||||
|
class AspectRatioLabel : public QLabel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit AspectRatioLabel(QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
void setOriginalPixmap(const QPixmap& pixmap);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void resizeEvent(QResizeEvent* event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateScaledPixmap();
|
||||||
|
QPixmap m_originalPixmap;
|
||||||
|
};
|
||||||
@ -486,7 +486,7 @@ sizePolicy1.setHeightForWidth(graphicsView_delete->sizePolicy().hasHeightForWidt
|
|||||||
initControlTabwidget();
|
initControlTabwidget();
|
||||||
m_tabManager = new TabManager(ui.controlTabWidget, this);
|
m_tabManager = new TabManager(ui.controlTabWidget, this);
|
||||||
|
|
||||||
ui.mDockWidgetSpectrometer->setWidget(tmp(ui.dockWidgetContents_4));
|
ui.mDockWidgetSpectrometer->setWidget(tmp(ui.controlContents));
|
||||||
|
|
||||||
//3D模型看板
|
//3D模型看板
|
||||||
ui.mDockWidgetSimulator->setTile(QString::fromLocal8Bit("3D模型"));
|
ui.mDockWidgetSimulator->setTile(QString::fromLocal8Bit("3D模型"));
|
||||||
@ -949,7 +949,21 @@ void HPPA::updateImagerPicture(const QString& actionName)
|
|||||||
QPixmap pixmap(picPath);
|
QPixmap pixmap(picPath);
|
||||||
if (!pixmap.isNull())
|
if (!pixmap.isNull())
|
||||||
{
|
{
|
||||||
ui.imagerPictureLabel->setPixmap(pixmap);
|
QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
|
||||||
|
const int threshold = 220;
|
||||||
|
for (int y = 0; y < img.height(); ++y)
|
||||||
|
{
|
||||||
|
QRgb* line = reinterpret_cast<QRgb*>(img.scanLine(y));
|
||||||
|
for (int x = 0; x < img.width(); ++x)
|
||||||
|
{
|
||||||
|
if (qRed(line[x]) >= threshold && qGreen(line[x]) >= threshold && qBlue(line[x]) >= threshold)
|
||||||
|
{
|
||||||
|
line[x] = qRgba(qRed(line[x]), qGreen(line[x]), qBlue(line[x]), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ui.imagerPictureLabel->setAttribute(Qt::WA_TranslucentBackground);
|
||||||
|
ui.imagerPictureLabel->setOriginalPixmap(QPixmap::fromImage(img));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -67,6 +67,8 @@
|
|||||||
#include "MapToolSpectral.h"
|
#include "MapToolSpectral.h"
|
||||||
#include "MapTools.h"
|
#include "MapTools.h"
|
||||||
|
|
||||||
|
#include "AspectRatioLabel.h"
|
||||||
|
|
||||||
#define PI 3.1415926
|
#define PI 3.1415926
|
||||||
|
|
||||||
QT_CHARTS_USE_NAMESPACE//QChartView 使用 需要加宏, 否则无法使用
|
QT_CHARTS_USE_NAMESPACE//QChartView 使用 需要加宏, 否则无法使用
|
||||||
|
|||||||
20
HPPA/HPPA.ui
20
HPPA/HPPA.ui
@ -251,9 +251,9 @@ QToolBar QToolButton:hover {
|
|||||||
<attribute name="dockWidgetArea">
|
<attribute name="dockWidgetArea">
|
||||||
<number>2</number>
|
<number>2</number>
|
||||||
</attribute>
|
</attribute>
|
||||||
<widget class="QWidget" name="dockWidgetContents_4">
|
<widget class="QWidget" name="controlContents">
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">QWidget #dockWidgetContents_4
|
<string notr="true">QWidget #controlContents
|
||||||
{
|
{
|
||||||
background-color: #0E1C4C;
|
background-color: #0E1C4C;
|
||||||
|
|
||||||
@ -424,22 +424,13 @@ QSlider::handle:horizontal:pressed {
|
|||||||
<number>10</number>
|
<number>10</number>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="imagerPictureLabel">
|
<widget class="AspectRatioLabel" name="imagerPictureLabel">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
|
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<property name="scaledContents">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
@ -1173,6 +1164,11 @@ QPushButton:pressed
|
|||||||
<header>CustomDockWidgetBase.h</header>
|
<header>CustomDockWidgetBase.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>AspectRatioLabel</class>
|
||||||
|
<extends>QLabel</extends>
|
||||||
|
<header>AspectRatioLabel.h</header>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="HPPA.qrc"/>
|
<include location="HPPA.qrc"/>
|
||||||
|
|||||||
@ -106,6 +106,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="aboutWindow.cpp" />
|
<ClCompile Include="aboutWindow.cpp" />
|
||||||
<ClCompile Include="adjustTable.cpp" />
|
<ClCompile Include="adjustTable.cpp" />
|
||||||
|
<ClCompile Include="AspectRatioLabel.cpp" />
|
||||||
<ClCompile Include="CaptureCoordinator.cpp" />
|
<ClCompile Include="CaptureCoordinator.cpp" />
|
||||||
<ClCompile Include="Carousel.cpp" />
|
<ClCompile Include="Carousel.cpp" />
|
||||||
<ClCompile Include="Corning410Imager.cpp" />
|
<ClCompile Include="Corning410Imager.cpp" />
|
||||||
@ -194,6 +195,7 @@
|
|||||||
<QtMoc Include="CustomDockWidgetBase.h" />
|
<QtMoc Include="CustomDockWidgetBase.h" />
|
||||||
<QtMoc Include="Carousel.h" />
|
<QtMoc Include="Carousel.h" />
|
||||||
<QtMoc Include="imageControl.h" />
|
<QtMoc Include="imageControl.h" />
|
||||||
|
<QtMoc Include="AspectRatioLabel.h" />
|
||||||
<ClInclude Include="imager_base.h" />
|
<ClInclude Include="imager_base.h" />
|
||||||
<ClInclude Include="irisximeaimager.h" />
|
<ClInclude Include="irisximeaimager.h" />
|
||||||
<QtMoc Include="OneMotorControl.h" />
|
<QtMoc Include="OneMotorControl.h" />
|
||||||
|
|||||||
@ -190,6 +190,9 @@
|
|||||||
<ClCompile Include="MapTools.cpp">
|
<ClCompile Include="MapTools.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="AspectRatioLabel.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtMoc Include="fileOperation.h">
|
<QtMoc Include="fileOperation.h">
|
||||||
@ -306,6 +309,9 @@
|
|||||||
<QtMoc Include="MapTools.h">
|
<QtMoc Include="MapTools.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</QtMoc>
|
</QtMoc>
|
||||||
|
<QtMoc Include="AspectRatioLabel.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</QtMoc>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="imageProcessor.h">
|
<ClInclude Include="imageProcessor.h">
|
||||||
|
|||||||
@ -196,7 +196,7 @@ QPushButton:pressed
|
|||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="pixmap">
|
<property name="pixmap">
|
||||||
<pixmap>C:/Users/73505/.designer/backup/icon/all/png/Group 356_slices/Group 356.png</pixmap>
|
<pixmap>icon/all/png/Group 356_slices/Group 356@2x.png</pixmap>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="widget_2" native="true">
|
<widget class="QWidget" name="widget_2" native="true">
|
||||||
|
|||||||
Reference in New Issue
Block a user