unsigned char として表される操作されたピクセル (グレー スケール) を表示しようとしましたが、失敗しました。
コードは次のとおりです。
#include "mainwindow.h"
#include <QApplication>
#include "qimage.h"
#include <QImage>
#include <QLabel>
#include <QColor>
#include "qcolor.h"
#include <Qdebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
int height;
int width;
unsigned char *p, *p_begin;
QImage img("C:\\Users\\Owner\\Pictures\\2013-09-26\\IMG_0836.JPG");
height = img.height();
width = img.width();
p = (unsigned char *)malloc(height * width * sizeof(unsigned char));
p_begin = p;
for (int row = 0; row < height; ++row)
{
for (int col = 0; col < width; ++col)
{
QColor clrCurrent( img.pixel( col, row ));
*p = (unsigned char)((clrCurrent.green() * 0.587) + (clrCurrent.blue() * 0.114) + (clrCurrent.red() * 0.299));
p++;
}
}
p = p_begin;
for ( int row = 0; row < height; ++row )
{
for (int col = 0; col < width; ++col)
{
QColor clrCurrent(img.pixel(col, row));
clrCurrent.setBlue((int)(*p));
clrCurrent.setGreen((int)(*p));
clrCurrent.setRed((int)(*p));
p++;
}
}
QLabel myLabel;
myLabel.setPixmap(QPixmap::fromImage(img));
myLabel.show();
return a.exec();
}
理由はよくわかりませんが、表現されている画像は元の画像であり、グレースケール化する必要がある操作された画像ではありません。運がないのでネットで見つけようとしましたが、アイデアはありますか?事前にthx。