Qt图像处理技术五:图像的翻转(横向,竖向)
效果图
竖直翻转(两种方法):
QImage Vertical(const QImage &origin)
{
QImage newImage(QSize(origin.width(), origin.height()), QImage::Format_ARGB32);
QColor tmpColor;
int r, g, b;
for (int x = 0; x < newImage.width(); x++) {
for (int y = 0; y < newImage.height(); y++) {
tmpColor = QColor(origin.pixel(x, y));
r = tmpColor.red();
g = tmpColor.green();
b = tmpColor.blue();
newImage.setPixel(x, newImage.height() - y - 1, qRgb(r, g, b));
}
}
return newImage;
}
QImage QImageAPI::Vertical(const QImage &origin)
{
QImage newImage(QSize(origin.width(), origin.height()), QImage::Format_ARGB32);
newImage=origin.mirrored(false, true);
return newImage;
}
水平翻转(两种方法):
QImage QImageAPI::Horizontal(const QImage &origin)
{
QImage newImage(QSize(origin.width(), origin.height()), QImage::Format_ARGB32);
QColor tmpColor;
int r, g, b;
for (int x = 0; x < newImage.width(); x++) {
for (int y = 0; y < newImage.height(); y++) {
tmpColor = QColor(origin.pixel(x, y));
r = tmpColor.red();
g = tmpColor.green();
b = tmpColor.blue();
newImage.setPixel(newImage.width() - x - 1, y, qRgb(r, g, b));
}
}
return newImage;
}
QImage QImageAPI::Horizontal(const QImage &origin)
{
QImage newImage(QSize(origin.width(), origin.height()), QImage::Format_ARGB32);
newImage=origin.mirrored(true, false);
return newImage;
}