简体   繁体   English

如何使用 QT 4 将 TIF 文件转换为 C++98 中的 BMP 文件?

[英]How to convert a TIF file into a BMP file in C++98 using QT 4?

I am new in C++.我是 C++ 的新手。 How can I convert a TIF file into a BMP file in C++98?如何在 C++98 中将 TIF 文件转换为 BMP 文件?

Here is my "newForm.h".Here is private slots for loading tiff and coverting the image.这是我的“newForm.h”。这是用于加载 tiff 和覆盖图像的私人插槽。

#ifndef _NEWFORM_H
#define _NEWFORM_H

#include <QMainWindow>
#include <QFileDialog>
#include <QDebug>

#include "ui_newForm.h"

QT_BEGIN_NAMESPACE
namespace Ui { class newForm; }
QT_END_NAMESPACE

class newForm : public QDialog {
    Q_OBJECT
public:
    newForm();
    virtual ~newForm();

private slots:
    void on_load_tiff_PushButton_clicked();
    void on_bmp_PushButton_convert();

private:
    QString mResourceDir;
    Ui::newForm widget;
};

#endif /* _NEWFORM_H */

Here is my "main.cpp" in which i show the "newForm".这是我的“main.cpp”,其中显示了“newForm”。

#include <QApplication>
#include "newForm.h"

int main(int argc, char *argv[]) {
    // initialize resources, if needed
    // Q_INIT_RESOURCE(resfile);

    QApplication app(argc, argv);
    newForm a;
    a.show();
    
    // create and show your widgets here

    return app.exec();
}

Here is "newForm.cpp".Here is on_load_tiff_PushButton_clicked which load tiff image.I want to convert tiff image into bitmap image using on_bitmap_PushButton_convert .how i can do that这是“ newForm.cpp ”。这是加载 tiff 图像的 on_load_tiff_PushButton_clicked。我想使用on_bitmap_PushButton_convert将 tiff 图像转换为 bitmap 图像。我该怎么做

#include "newForm.h"
#include <QMainWindow>
#include <QFileDialog>
#include <QDebug>

newForm::newForm() {
    widget.setupUi(this);
    mResourceDir = "/root/NetBeansProjects/TIF_TO_BMP/file.tiff";
    
    connect(widget.pushButton, SIGNAL(clicked()), this, SLOT(on_load_tiff_PushButton_clicked()));
    connect(widget.pushButton_2, SIGNAL(clicked()), this, SLOT(on_bitmap_PushButton_convert()));
      
}
QString filename ;
void newForm::on_load_tiff_PushButton_clicked()
{
     filename = QFileDialog::getOpenFileName(this,tr("Load Image"),mResourceDir,tr("Images (*.jpg *.tiff)"));
    if (filename.isEmpty()){
        return;
    }
    QPixmap p(filename);
    if (! widget.graphicsView->scene()){
        qDebug() << "No Scene!";
        QGraphicsScene *scene = new QGraphicsScene(this);
        widget.graphicsView->setScene(scene);
    }
    widget.graphicsView->scene()->addPixmap(p);
}
void newForm::on_bitmap_PushButton_convert()
{
    if (widget.graphicsView->scene()) {
        QPixmap p(filename);
        QByteArray bytes;
        QBuffer buffer(&bytes);
        buffer.open(QIODevice::WriteOnly);
        p.save(&buffer, "BMP"); // writes pixmap into bytes in PNG format
       // widget.graphicsView->scene()->clear();             
    }
}
newForm::~newForm() {
}

Here is image of the "newForm.ui"这是“newForm.ui”的图像

在此处输入图像描述

I want this make "bmp" image on this directory /root/NetBeansProjects/TIF_TO_BMP/file.tiff in centos6.8 which is not made on clicking the Convert_To_BMP button that calls on_bitmap_PushButton_convert() .我希望在 centos6.8 中的此目录/root/NetBeansProjects/TIF_TO_BMP/file.tiff上制作“bmp”图像,这不是在单击调用on_bitmap_PushButton_convert()Convert_To_BMP按钮时制作的。

You could use stb which is a header-only library.您可以使用stb这是一个仅限标头的库。

https://github.com/nothings/stb/blob/master/tests/image_write_test.c https://github.com/nothings/stb/blob/master/tests/image_write_test.c

   // make a RGB version of the template image
   // use red on blue to detect R<->B swaps
   unsigned char img6x5_rgb[6*5*3];
   float img6x5_rgbf[6*5*3];
   int i;

   for (i = 0; i < 6*5; i++) {
      int on = img6x5_template[i] == '*';
      img6x5_rgb[i*3 + 0] = on ? 255 : 0;
      img6x5_rgb[i*3 + 1] = 0;
      img6x5_rgb[i*3 + 2] = on ? 0 : 255;

      img6x5_rgbf[i*3 + 0] = on ? 1.0f : 0.0f;
      img6x5_rgbf[i*3 + 1] = 0.0f;
      img6x5_rgbf[i*3 + 2] = on ? 0.0f : 1.0f;
   }

   stbi_write_png("output/wr6x5_regular.png", 6, 5, 3, img6x5_rgb, 6*3);
   stbi_write_bmp("output/wr6x5_regular.bmp", 6, 5, 3, img6x5_rgb);
   stbi_write_tga("output/wr6x5_regular.tga", 6, 5, 3, img6x5_rgb);
   stbi_write_jpg("output/wr6x5_regular.jpg", 6, 5, 3, img6x5_rgb, 95);
   stbi_write_hdr("output/wr6x5_regular.hdr", 6, 5, 3, img6x5_rgbf);

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

相关问题 c++ 98中如何过滤结果以仅获取output结果linux中的文件名 - How to filter out the result to get only file names in output result linux in c++98 如何在针对C ++ 11和C ++ 98的单一版本中使用cmake 2.8.2进行共享库创建时每次重新编译源文件? - How to recompile source file every time while using cmake 2.8.2 in single build for c++11 and c++98 for shared library creation? 如何在CLion中严格针对C ++ 98 - How to strictly target C++98 in CLion 如何强制Qt QMake项目使用C ++ 98标准? - How is possible to force Qt QMake project to use C++98 standard? 如何在没有提升的情况下将C ++ 11代码转换为C ++ 98? - How can I convert the C++11 code to C++98 without boost? 如何转换自动(用于矢量<string> ) 从 c++11 到 c++98?</string> - How to convert auto (for vector<string>) from c++11 to c++98? 如何转换 map<int, string> 从 c++11 到 c++98?</int,> - How to convert map<int, string> from c++11 to c++98? 无法编译C ++ file.cpp。 C ++ 98模式 - Can't compile C++ file.cpp. C++98 mode 在 map 中读取 FILE 和存储数据<string, vector<string> &gt; C++98</string,> - To read FILE and store data in map<string, vector<string>> c++98 在 c++98 Linux 中读取文件名作为命令行参数并执行文件操作“打开” - To read fileName as commandLine argument and perform file Operation “open” in c++98 Linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM