Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. RGB image to CMYK gdi+

RGB image to CMYK gdi+

Scheduled Pinned Locked Moved C / C++ / MFC
c++dotnetwinformsgraphicsadobe
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gopi Nath
    wrote on last edited by
    #1

    Hello, I am trying to adjust the color balance (CYMK) of an image like this is in photoshop or some other applications. From examples, i tried changing the current RGB to CMYK (for each pixel) using the below code.

    for (int i = 0; i < width; i++)
    {
    for (int j = 0; j < height; j++)
    {
    tmpbmp->GetPixel(i, j, &clr);

    		R = clr.GetR();
    		G = clr.GetG();
    		B = clr.GetB();
    
    		c = \_cyanclr / 255.0; // \_cyanclr - user input in %
    		m = \_magentaclr / 255.0;
    		y = \_yellowclr / 255.0;
    		k = \_blackclr / 255.0;
    
    		rr = c \* (1.0 - k) + k;
    		gg = m \* (1.0 - k) + k;
    		bb = y \* (1.0 - k) + k;
    
    		rr = (1.0 - rr) \* 255.0 + 0.5;
    		gg = (1.0 - gg) \* 255.0 + 0.5;
    		bb = (1.0 - bb) \* 255.0 + 0.5;
    		
           // here i dont know how to adjust new RGB with old one
    		R += rr;
    		G += gg;
    		B += bb;
    
    		R = R < 0 ? 0 : (R > 255) ? 255 : R;
    		G = G < 0 ? 0 : (G > 255) ? 255 : G;
    		B = B < 0 ? 0 : (B > 255) ? 255 : B;			
    
    		output->SetPixel(i, j, Gdiplus::Color(R, G, B));
    	}
    }
    

    With this code, i am not getting the same result like in photoshop and other applications. I am not sure whether I am doing in right method or not. Please suggest. I am using C++ and gdi+. Regards, Gopinath.

    L R 2 Replies Last reply
    0
    • G Gopi Nath

      Hello, I am trying to adjust the color balance (CYMK) of an image like this is in photoshop or some other applications. From examples, i tried changing the current RGB to CMYK (for each pixel) using the below code.

      for (int i = 0; i < width; i++)
      {
      for (int j = 0; j < height; j++)
      {
      tmpbmp->GetPixel(i, j, &clr);

      		R = clr.GetR();
      		G = clr.GetG();
      		B = clr.GetB();
      
      		c = \_cyanclr / 255.0; // \_cyanclr - user input in %
      		m = \_magentaclr / 255.0;
      		y = \_yellowclr / 255.0;
      		k = \_blackclr / 255.0;
      
      		rr = c \* (1.0 - k) + k;
      		gg = m \* (1.0 - k) + k;
      		bb = y \* (1.0 - k) + k;
      
      		rr = (1.0 - rr) \* 255.0 + 0.5;
      		gg = (1.0 - gg) \* 255.0 + 0.5;
      		bb = (1.0 - bb) \* 255.0 + 0.5;
      		
             // here i dont know how to adjust new RGB with old one
      		R += rr;
      		G += gg;
      		B += bb;
      
      		R = R < 0 ? 0 : (R > 255) ? 255 : R;
      		G = G < 0 ? 0 : (G > 255) ? 255 : G;
      		B = B < 0 ? 0 : (B > 255) ? 255 : B;			
      
      		output->SetPixel(i, j, Gdiplus::Color(R, G, B));
      	}
      }
      

      With this code, i am not getting the same result like in photoshop and other applications. I am not sure whether I am doing in right method or not. Please suggest. I am using C++ and gdi+. Regards, Gopinath.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      It is not clear exactly what your problem is or what adjustments you are trying to make to your colours. Maybe you could explain with some examples.

      1 Reply Last reply
      0
      • G Gopi Nath

        Hello, I am trying to adjust the color balance (CYMK) of an image like this is in photoshop or some other applications. From examples, i tried changing the current RGB to CMYK (for each pixel) using the below code.

        for (int i = 0; i < width; i++)
        {
        for (int j = 0; j < height; j++)
        {
        tmpbmp->GetPixel(i, j, &clr);

        		R = clr.GetR();
        		G = clr.GetG();
        		B = clr.GetB();
        
        		c = \_cyanclr / 255.0; // \_cyanclr - user input in %
        		m = \_magentaclr / 255.0;
        		y = \_yellowclr / 255.0;
        		k = \_blackclr / 255.0;
        
        		rr = c \* (1.0 - k) + k;
        		gg = m \* (1.0 - k) + k;
        		bb = y \* (1.0 - k) + k;
        
        		rr = (1.0 - rr) \* 255.0 + 0.5;
        		gg = (1.0 - gg) \* 255.0 + 0.5;
        		bb = (1.0 - bb) \* 255.0 + 0.5;
        		
               // here i dont know how to adjust new RGB with old one
        		R += rr;
        		G += gg;
        		B += bb;
        
        		R = R < 0 ? 0 : (R > 255) ? 255 : R;
        		G = G < 0 ? 0 : (G > 255) ? 255 : G;
        		B = B < 0 ? 0 : (B > 255) ? 255 : B;			
        
        		output->SetPixel(i, j, Gdiplus::Color(R, G, B));
        	}
        }
        

        With this code, i am not getting the same result like in photoshop and other applications. I am not sure whether I am doing in right method or not. Please suggest. I am using C++ and gdi+. Regards, Gopinath.

        R Offline
        R Offline
        RedDk
        wrote on last edited by
        #3

        Whatever works is the right method. There's no "not". Unless all one does is repost code they dug up from elsewhere and hasn't the foggiest idea what they're doing THAT for. :thumbsdown:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups