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

  • Home
  • SEARCH
  • 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 7058975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:10:37+00:00 2026-05-28T04:10:37+00:00

Hello all C++ Experts, It’s me again. I will get straight to the point.

  • 0

Hello all C++ Experts,

It’s me again. I will get straight to the point.

I’ve successfully got the bitmap image rgb colors pixel which is (blue – 178, green – 130 and red 131).

What I do want to do next is to loop through the pixels and make it such that the picture will be totally blue. (Eg. Blue – 255, green – 0, red – 0)

I did tried a couple of for loops but it does not work, therefore, requiring assistance!

/*for (int i = 0; i < test; i++) 
{ 
image[i].rgbtBlue; 
image[i].rgbtGreen; 
image[i].rgbtRed; 
}*/ 

But obviously it does not work, that was why i needed the assistance. To add it on, hfile was being initialized for other purposes so i did not think it was relevant. Appreciated all the comments, thank you.

Thank you! As below is the code.

P.S: Using Microsoft Visual Studio 2010 – Win32 application, not Console.

#include "stdafx.h"
#include "winmain.h"
#include "Resource.h"
#include <stdio.h>
#include <windows.h>
#include <iostream>
#include <CommDlg.h>
#include <stdint.h>
#include <string>
#include <WinGDI.h>

HANDLE hfile2; 
DWORD written; 
BITMAPFILEHEADER bfh; 
BITMAPINFOHEADER bih; 
RGBTRIPLE *image;

hfile2 = CreateFile(ofn.lpstrFile`, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_OVERLAPPED, NULL);
//Read the header
ReadFile(hfile, &bfh, sizeof(bfh), &written, NULL);
ReadFile(hfile, &bih, sizeof(bih), &written, NULL);

// Read image
int imagesize = bih.biWidth * bih.biHeight; // Helps you allocate memory for the image
image = new RGBTRIPLE[imagesize]; // Create a new image (I'm creating an array during runtime
ReadFile(hfile, image, imagesize * sizeof(RGBTRIPLE), &written, NULL); // Reads it off the disk
get_pixel(bih.biWidth, bih.biHeight);
int test = bih.biHeight * bih.biWidth * bih.biBitCount;

RGBTRIPLE get_pixel(int x,int y)
{
    // Image define from earlier
    return image[(bih.biHeight-1-y)*bih.biWidth+x];
}
  • 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-28T04:10:37+00:00Added an answer on May 28, 2026 at 4:10 am

    Your comment is pretty much right on. Each element image[i] is a RGBTRIPLE variable, which you can read and write. Therefore, setpixel is straightforward:

    void set_pixel(int x,int y, RGBTRIPLE color)
    {
        image[(bih.biHeight-1-y)*bih.biWidth+x] = color;
    }
    

    You see that the same code is used to select the right pixel of the image. You’ll probably want to define a const RGBTRIPLE blue; constant.

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

Sidebar

Related Questions

Problem Hello all! I have this code which takes my jpg image loops through
Hello to all jQuery enthusiasts and experts!! I currently use on a project this
Hello all I was hoping to get some help with inported this class to
Hello all I have a simple Spring application which will not end as there
hello expert, i want to get information of all apk in mobile, like name,icon,date
Hello all Windows Mobile Experts! I have really drowned in the world of developing
Hello all this is what I got: NSN:&nbsp;<input type=text name=filterCriteria(NSN).values value=/> <input type=hidden name=filterCriteria(NSN).fieldName
Hello all you helpful folks @ stackoverflow! Best resources for Java GUI's? Looking at
Hello all i'm turning objects on (adding the class .active) and off on a
hello all I have a small dialog which I created dynamically, which has a

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.