Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:00:42+00:00 2026-06-06T15:00:42+00:00

I need to extract pixel information and populate a QPixmap to be used in

  • 0

I need to extract pixel information and populate a QPixmap to be used in my Qt program.

I am currently doing this in a 2-step process.

  • SDL_Surface to Windows .bmp using SDL_SaveBMP()
  • .bmp to QImage
  • QImage to QPixmap

I am storing the intermediate .bmp in memory. But overall, I am not happy with this approach because it involves file-format conversion overheads related to .bmp

Any better suggestion?

Edit: Sharing the final working code, from jrok’s answer plus experimenting with pixel formats

SDL_Surface *screen = ... /* Whatever surface you want to copy from */
SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
                       screen->w, screen->h,
                       24, rmask, gmask, bmask, amask);
SDL_BlitSurface(screen,NULL, surface,NULL);
QImage img(static_cast<uchar*>(surface->pixels),
                       surface->w, surface->h, QImage::Format_RGB888);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:00:43+00:00Added an answer on June 6, 2026 at 3:00 pm

    One of QImage constructors takes raw image data. You can pass it pixels pointer from SDL_Surface structure:

    SDL_Surface* surf = /* get surface */
    
    QImage img(static_cast<uchar*>(surf->pixels), surf->w, surf->h, QImage::Format_RGB32);
    

    The last parameter will depend on the SDL_PixelFormat of your SDL_Surface.

    Then you can simply make QPixmap from QImage:

    QPixmap = QPixmap::fromImage(img);
    

    QPixmap::fromImage() reference

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to extract each pixel color from a png image and store it
I need to extract some information from not very complicated HTML pages in web.
I need to extract the same type of information (e.g. First name, Last Name,
I need to extract a value from a process array to myArray: File: MyClass.vb
I need a way I can read the lines and extract the pixel info
I need to extract the path info using Path.GetFileName() , and this function doesn't
I need to extract two seperate information from a string. For example, $string =
I need to extract the word following 'NN' in this particular sentence? (ROOT (SBARQ
I need to extract information from iTunes Music Library.xml file. Since the xml is
I need to extract the image url from this enclosure. How can i access

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.