Jump to content
  • Advertisement
Sign in to follow this  
As-12

How to query width height and bits from SDL?

This topic is 4376 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have read SDL-Image Documentations. But it said only How to load but no query the state of the images. Anyideas to query width , height and bits from SDL-Image ?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by As-12
I have read SDL-Image Documentations. But it said only How to load but no query the state of the images. Anyideas to query width , height and bits from SDL-Image ?
I've never used SDL but it appears that all of the Loading functions return a pointer to an SDL_Surface, which appears to be a struct that holds the information you want.

Share this post


Link to post
Share on other sites

SDL_Surface *surf = SDL_LoadBMP("mmmhmmm.bmp");
int width = surf->w; //Get the width
int height = surf ->h; //Get the height
unsigned char *data = (unsigned char)surf->pixels; //Get the image data


Also you can cheak what format the data in pixels is using the format member of SDL_Surface.

Share this post


Link to post
Share on other sites
Quote:
Original post by Taymo

SDL_Surface *surf = SDL_LoadBMP("mmmhmmm.bmp");
int width = surf->w; //Get the width
int height = surf ->h; //Get the height
unsigned char *data = (unsigned char)surf->pixels; //Get the image data


Also you can cheak what format the data in pixels is using the format member of SDL_Surface.


Just make sure that if you are accessing the pixel data, you lock the surface if it needs to be locked (AKA, if it's a hardware surface instead of a software surface).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!