|
你不能就这么把 data 给 delete 了。
看文档:
The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer cleanupFunction along with an extra pointer cleanupInfo that will be called when the last copy is destroyed.
你应该用 cleanupFunction 来清理它。
不过我更推荐你类似这么写
- QImage img(width,height,QImage::Format_RGB32);
- for (int y=0; y<height; ++y)
- {
- QRgb* line = reinterpret_cast<QRgb*>(img.scanLine(y));
- for (int x=0; x<width; ++x)
- {
- // do something
- r = ...;
- g = ...;
- b = ...;
- line[x] = qRgb(r,g,b);
- }
- }
复制代码 |
|