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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:31:37+00:00 2026-05-14T00:31:37+00:00

Problem Hello all! I have this code which takes my jpg image loops through

  • 0

Problem

Hello all!

I have this code which takes my jpg image loops through altering pixels and finally saving it as a png type. The problem is that the resulting image has a bit depth of 32 bits. I need it to be 24 bit, can any one shiny some light on the correct method of setting it? Am I along the right tracks looking at setting the pixel format to PixelFormat24bppRGB?

Code

static inline void Brighten(Gdiplus::Bitmap* img)
{
    int width = img->GetWidth()/8,height = img->GetHeight(), max = (width*height),r,g,b;
    Gdiplus::Color pixel;   
    for(int a = 0,x = 0, y = -1; a < max; ++a)
    {
        x = a%width;    
        if(x == 0)
            ++y;
        img->GetPixel(x,y,&pixel);
        r = pixel.GetR();
        g = pixel.GetG();
        b = pixel.GetB();
        if (r > 245) r = 245; 
        if (g > 245) g = 245;  
        if (b > 245) b = 245; 
        r += 10;
        g += 10;
        b += 10;
        pixel = Gdiplus::Color(r,g,b);
        img->SetPixel(x,y,pixel);;
    }
}

ULONG_PTR m_dwToken = 0;
Gdiplus::GdiplusStartupInput input;
Gdiplus::GdiplusStartupOutput output;
Gdiplus::GdiplusStartup( &m_dwToken, &input, &output );
USES_CONVERSION_EX;
Gdiplus::ImageCodecInfo* pEncoders = static_cast< Gdiplus::ImageCodecInfo* >( _ATL_SAFE_ALLOCA(1040, _ATL_SAFE_ALLOCA_DEF_THRESHOLD));
Gdiplus::DllExports::GdipGetImageEncoders(5, 1040, pEncoders );
CLSID clsidEncoder = pEncoders[4].Clsid;

Gdiplus::Bitmap img1((CT2W)L"IMG_1.JPG");
Brighten(&img1);
img1.Save((CT2W)L"IMG_1_R3.PNG",&clsidEncoder,NULL);

Thanks in advance!

  • 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-14T00:31:37+00:00Added an answer on May 14, 2026 at 12:31 am

    Ok I actually fixed it, I’ve used the LockBits() to access the bits directly and modify them, this gives me a much needed performance boost and keeps it as a 24bit image.

    static inline void Brighten(Gdiplus::Bitmap* img)
    {
        int width = img->GetWidth(),height = img->GetHeight(),r,g,b;
        Gdiplus::Rect rect(0,0,width,height);
        Gdiplus::BitmapData data;
        img->LockBits(&rect,Gdiplus::ImageLockModeWrite,PixelFormat24bppRGB,&data);
        int stride = data.Stride,offset = stride - width*3;
        byte * p1 = (byte *)(void *)data.Scan0;
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                r = p1[0];
                g = p1[1];
                b = p1[2];
                if (r > 245) r = 245; 
                if (g > 245) g = 245;  
                if (b > 245) b = 245; 
                r += 10;
                g += 10;
                b += 10;    
                p1[0] = r;
                p1[1] = g;
                p1[2] = b;
                p1 += 3;
            }
            p1 += offset;
        }
        img->UnlockBits(&data);     
    }
    

    Thanks for all of your help!

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

Sidebar

Ask A Question

Stats

  • Questions 380k
  • Answers 380k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I definitely wouldn't bother with it. It's a site for… May 14, 2026 at 9:57 pm
  • Editorial Team
    Editorial Team added an answer Step 4: You click back and click “Resend information” —… May 14, 2026 at 9:57 pm
  • Editorial Team
    Editorial Team added an answer From my experience with Alfresco, this is going to take… May 14, 2026 at 9:57 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.