Magick ++始终生成黑色图像

时间:2019-10-10 16:06:25

标签: c++ imagemagick

这是应该生成位图的代码: 像素来自GetPixels(),它是使用设备上下文获取像素的Windows函数。我验证了像素数据的确不仅总是相同的数字。

void Bitmap::writeBitmap(std::string filename, Matrix<COLORREF> pixels, int width, int height) {

    Magick::InitializeMagick("");
    Color* white = new Color("white");
    Image* image = new Image(Geometry(120, 120), *white);
    image->type(TrueColorType);

    image->modifyImage();

    Pixels* view = new Pixels(*image);

    size_t columns = 120; size_t rows = 120;

    Quantum* pixelsPointer = view->get(0, 0, 120, 120);
    for (ssize_t row = 0; row < rows; row++) {
        for (ssize_t column = 0; column < columns; column++) {
            COLORREF cr = pixels.get(row, column);
            std::cout << GetRValue(cr) << "|" << GetGValue(cr) << "|" << GetBValue(cr) << std::endl;

            *pixelsPointer++ = GetRValue(pixels.get(row, column));
            *pixelsPointer++ = GetGValue(pixels.get(row, column));
            *pixelsPointer++ = GetBValue(pixels.get(row, column));
        }
    }
    view->sync();

    image->write(filename);

}

0 个答案:

没有答案