【发布时间】:2018-11-28 00:55:01
【问题描述】:
我想控制加载图像的颜色,但在尝试备份像素数据时遇到了问题。我的代码如下所示:
Uint32* pixels, oriPixels;
SDL_Surface* image;
void BackupPixelData()
{
pixels = (Uint32*)image->pixels;
oriPixels = new Uint32[image->w * image->h];
for (int i = 0; i < image->w * image->h; i++)
{
oriPixels[i] = pixels[i]; //This causes an access violation midway through
*(oriPixels + i) = *(pixels + i); //Using this method does not cause any crash, but the image will have artifacts
}
}
我可以通过将 oriPixels 更改为 Uint32 的向量来使代码工作,并且我没有遇到任何问题(可以使用 oriPixels 将图像恢复为原始颜色)。
如何正确加载像素数据?
图像是 32 位的。
【问题讨论】: