簡體   English   中英

將原始數據另存為新文件

[英]Save raw data as new file

我正在獲取圖像行數據並將其保存在無符號char數組中。 接下來,我嘗試根據該數據創建新的圖像文件。

我如何獲取數據:

for(int i = 0; i < x; i++) {
        for(int j = 0; j < y; j++) {
            byteArray[i][j] = *((image.bits() + i) + j);
        }
    }

其中x->圖片寬度,y->圖片高度。 另外,據我了解,bits()返回指向第一個像素數據的指針,因此使用“ i”和“ j”可以移動該指針。 有了這個,我得到了255、255、120等值(r,g,b,像素值)的數組。

我如何創建新圖像:

void saveFile(unsigned char **array, const int &x, const int &y) {
    QImage newImage(x, y, QImage::Format_ARGB32);
    newImage.loadFromData((const unsigned char*)array, x * y, "JPG");
    bool success = newImage.save("przerobione", "JPG", -1);

    if(success == true) {
        qDebug() << "Zapisano!";
    }
    else {
        qDebug() << "nope";
    }
}

不幸的是,它從未創建文件。 我究竟做錯了什么 ?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM