0
PNG24像素我有,給定表面的getpixel
功能,讀取一個給定的像素的R,G,B和α值:我與Phosothop保存一個PNG圖像SDL2讀取由像素
void getpixel(SDL_Surface *surface, int x, int y) {
int bpp = surface->format->BytesPerPixel;
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
Uint8 red, green, blue, alpha;
SDL_GetRGBA(*p, surface->format, &red, &green, &blue, &alpha);
cout << (int)red << " " << (int)green << " " << (int)blue << " " << (int)alpha << endl;
}
「保存爲Web「,我選擇PNG24作爲格式。問題是,該功能只讀取紅色值,讀阿爾法爲0 我試圖強迫格式像這樣:
SDL_Surface* temp = IMG_Load(png_file_path.c_str());
SDL_Surface* image = SDL_ConvertSurfaceFormat(temp, SDL_PIXELFORMAT_RGBA8888, 0);
SDL_FreeSurface(temp);
這樣它只讀Alpha值,來代替。如何在SDL2中按像素讀取PNG像素?
24位不是指3個顏色分量(每個元素8位)?所以不會有alpha通道可以讀取...... – user673679