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 4073478
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:01:40+00:00 2026-05-20T17:01:40+00:00

I have an image I am trying to display in a QImage. This is

  • 0

I have an image I am trying to display in a QImage.

This is the snippet of code that populates the rows*cols image:

    rgbMapped[row][col * 3] = red;

    rgbMapped[row][col * 3 + 1] = green;

    rgbMapped[row][col * 3 + 2] = blue;

As you can see, my data buffer is “rows-high” and is “cols*3 wide”

rgbMapped is an unsigned char** array. So back in my QT code I have the following:

QImage *qi = new QImage(getWidth(), getHeight(), QImage::Format_RGB888);

for (int h = 0; h< getHeight(); h++){
    memcpy(qi->scanLine(h), rgbMapped[h], getWidth()*3);
}
QPixmap p(QPixmap::fromImage(*qi,Qt::ColorOnly));

if(scene.items().contains(item)){
    scene.removeItem(item);
}
item = new ImagePixmapItem(p);
scene.addItem(item);
ui->graphicsView->setScene(&scene);
ui->graphicsView->show();

ImagePixMapItem is a QGraphicsPixmapItem that I have created to allow me to intercept some mouse events, but I dindt do anyhting with any of the paint functions or anything.

When I run this code, my return comes back as an image that looks like my image, except there are three copies, one with a green tint, one looking yellow-ish and one with a noticeable purple tint.

It seems like maybe it would be the correct image if these three pieces of data were..overlayed on each other?

  • 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-05-20T17:01:40+00:00Added an answer on May 20, 2026 at 5:01 pm

    Just an assumption, but from the (wrong) colors you mentioned, I suspect the problem could be with your allocation/initialization code regarding the char **rgbMapped variable.
    Could you please post this code?

    I will try to write bellow a possibly correct(?) initialization code
    just to give you a hint which may help (I haven’t compile the code,
    therefore I apologize for any syntax errors).
    I use malloc() but you can also use the new() operator.

    // allocate a single buffer for all image pixels
    unsigned char *imgbuf = malloc(3 * getWidth() * getHeight());
    
    // allocate row pointers
    unsigned char **rgbMapped = malloc(getHeight() * sizeof (unsigned char *)); 
    
    // Initialize row pointers
    for (int h=0; h < getHeight(); h++)
    {
      *rgbMapped[h] = &imgbuf[h * 3 * getWidth()];
    }
    
    // ... do your processing
    
    // Free the image buffer & row pointers
    free(imgbuf);
    imgbuf = NULL;
    free(rgbMapped);
    rgbMapped = NULL;
    

    The important part is the initialization of row pointers (did you forget the *3?).
    Just my 2c.

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

Sidebar

Related Questions

I have this background image that is 175x175 but I am trying to make
I am trying to display image in each row. I have a switch to
i have a .png image that i am trying to display as a UIBarButtonItem
I'm trying to display image data read in from a binary file (I have
What I am trying to do is something like this: I have my image
So, I am trying to have this image show up in the fancy box
That's pretty much what I am trying to accomplish. To have each image appear
I'm trying to take an image that I have in a image object and
I'm trying to display an image returned from AFImageRequestOperation ImageRequestOperationWithRequest: but it appears that
I trying to display image in picture box. The application have two part. First

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.