将一张图片生成二进制文件

    QImage img;
    img.load("/home/a.bmp");
    QFile file("/home/home/a.dat");
    if (!file.open(QIODevice::ReadWrite))
        return -1;

    uchar* bits = img.bits();
    int bcount = img.byteCount();

    uchar* tmpImgData = (uchar*)malloc(bcount);
    memset (tmpImgData, 0, bcount);
    memcpy (tmpImgData, bits, bcount);

    file.write((char*)tmpImgData,bcount);
    file.close();

猜你喜欢

转载自blog.csdn.net/swif_N_F/article/details/78684986