RGB values from a bitmap
Hi, theres a project that I have been assigned and it entails reading colors from a bitmap. I need to be able to check the RGB values of each pixel. If anyone could suggest a way to do this I would be most grateful. Thanks
Totaly depends on the type of image. If you can restrict the type to bmp/tga etc you could find some image loaders at gametutorials.com or just google.
/P
Swedish: #Gamedev.se on EFNET
/P
Swedish: #Gamedev.se on EFNET
Swedish: #Gamedev.se on EFNET
This is the code I use for loding Bitmaps without AuxDIB:
hope that helped. obviously, you may have to change all the 256 to 512 or whatever. You could probably make it dynamic sized (using the BITMAP struct, can''t quite remember how, though).
------------------------------------------------------
Regret Nothing - Learn Everything
HBITMAP hBm=LoadBitmap(g_window->init.application->hInstance,MAKEINTRESOURCE(IDB_FONT)); // Get Handle for BitmapBYTE* pTexData=new BYTE[3*256*256]; // Make Space for BitmapHDC hdcTemp = CreateCompatibleDC(g_window->hDC);SelectObject(hdcTemp, hBm); // Get a DC for the Bitmapint i=0;COLORREF col;for(int y=0;y<256;y++){ //for each column and row for(int x=0;x<256;x++) { col=GetPixel(hdcTemp,x,255-y); // Get RGB of Pixel pTexData[i++]=GetRValue(col); // Get Red pTexData[i++]=GetGValue(col); // Get Green pTexData[i++]=GetBValue(col); // Get Blue }}ReleaseDC(g_window->hWnd,hdcTemp); // Free the DCDeleteObject(hBm); // Free the BitmapglGenTextures(1, texture); // Create the TextureglBindTexture(GL_TEXTURE_2D, texture[0]);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, pTexData);free(pTexData); // Free The Texture Image Memory
hope that helped. obviously, you may have to change all the 256 to 512 or whatever. You could probably make it dynamic sized (using the BITMAP struct, can''t quite remember how, though).
------------------------------------------------------
Regret Nothing - Learn Everything
------------------------------------------------------ Regret Nothing - Learn Everything
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement