打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
C++实现Photoshop色相/饱和度/明度功能

    本文用C++实现Photoshop色相/饱和度/明度功能,界面程序使用BCB6;图片操作采用GDI+。代码也可适用于其它C/C++编译器(可能要稍作修改)。 

   有关Photoshop饱和度调整原理可参见《GDI+ 在Delphi程序的应用 -- 图像饱和度调整》,明度调整原理可参见《GDI+ 在Delphi程序的应用 -- 仿Photoshop的明度调整》。

    色相/饱和度/明度功能头文件:

  1. #ifndef RgbHsbH  
  2. #define RgbHsbH  
  3.   
  4. #include <windows.h>  
  5. #include <algorithm>  
  6. using std::min;  
  7. using std::max;  
  8. #include <gdiplus.h>  
  9. using namespace Gdiplus;  
  10.   
  11. void GdipHSBAdjustment(Bitmap *Bmp, int hValue, int sValue, int bValue);  
  12.   
  13. #endif  

色相/饱和度/明度功能代码文件:

  1. #include "RgbHsb.h"  
  2.   
  3. inline void SwapRGB(int &a, int &b)  
  4. {  
  5.     a += b;  
  6.     b = a - b;  
  7.     a -= b;  
  8. }  
  9.   
  10. inline void CheckRGB(int &Value)  
  11. {  
  12.     if (Value < 0) Value = 0;  
  13.     else if (Value > 255) Value = 255;  
  14. }  
  15.   
  16. inline void AssignRGB(BYTE &R, BYTE &G, BYTE &B, int intR, int intG, int intB)  
  17. {  
  18.     R = intR;  
  19.     G = intG;  
  20.     B = intB;  
  21. }  
  22.   
  23. void SetBright(BYTE &R, BYTE &G, BYTE &B, int bValue)  
  24. {  
  25.     int intR = R;  
  26.     int intG = G;  
  27.     int intB = B;  
  28.     if (bValue > 0)  
  29.     {  
  30.         intR = intR + (255 - intR) * bValue / 255;  
  31.         intG = intG + (255 - intG) * bValue / 255;  
  32.         intB = intB + (255 - intB) * bValue / 255;  
  33.     }  
  34.     else if (bValue < 0)  
  35.     {  
  36.         intR = intR + intR * bValue / 255;  
  37.         intG = intG + intG * bValue / 255;  
  38.         intB = intB + intB * bValue / 255;  
  39.     }  
  40.     CheckRGB(intR);  
  41.     CheckRGB(intG);  
  42.     CheckRGB(intB);  
  43.     AssignRGB(R, G, B, intR, intG, intB);  
  44. }  
  45.   
  46. void SetHueAndSaturation(BYTE &R, BYTE &G, BYTE &B, int hValue, int sValue)  
  47. {  
  48.     int intR = R;  
  49.     int intG = G;  
  50.     int intB = B;  
  51.   
  52.     if (intR < intG)  
  53.         SwapRGB(intR, intG);  
  54.     if (intR < intB)  
  55.         SwapRGB(intR, intB);  
  56.     if (intB > intG)  
  57.         SwapRGB(intB, intG);  
  58.   
  59.     int delta = intR - intB;  
  60.     if (!delta) return;  
  61.   
  62.     int entire = intR + intB;  
  63.     int H, S, L = entire >> 1;  
  64.     if (L < 128)  
  65.         S = delta * 255 / entire;  
  66.     else  
  67.         S = delta * 255 / (510 - entire);  
  68.     if (hValue)  
  69.     {  
  70.         if (intR == R)  
  71.             H = (G - B) * 60 / delta;  
  72.         else if (intR == G)  
  73.             H = (B - R) * 60 / delta + 120;  
  74.         else  
  75.             H = (R - G) * 60 / delta + 240;  
  76.         H += hValue;  
  77.         if (H < 0) H += 360;  
  78.         else if (H > 360) H -= 360;  
  79.         int index = H / 60;  
  80.         int extra = H % 60;  
  81.         if (index & 1) extra = 60 - extra;  
  82.         extra = (extra * 255 + 30) / 60;  
  83.         intG = extra - (extra - 128) * (255 - S) / 255;  
  84.         int Lum = L - 128;  
  85.         if (Lum > 0)  
  86.             intG += (((255 - intG) * Lum + 64) / 128);  
  87.         else if (Lum < 0)  
  88.             intG += (intG * Lum / 128);  
  89.         CheckRGB(intG);  
  90.         switch (index)  
  91.         {  
  92.             case 1:  
  93.                 SwapRGB(intR, intG);  
  94.                 break;  
  95.             case 2:  
  96.                 SwapRGB(intR, intB);  
  97.                 SwapRGB(intG, intB);  
  98.                 break;  
  99.             case 3:  
  100.                 SwapRGB(intR, intB);  
  101.                 break;  
  102.             case 4:  
  103.                 SwapRGB(intR, intG);  
  104.                 SwapRGB(intG, intB);  
  105.                 break;  
  106.             case 5:  
  107.                 SwapRGB(intG, intB);  
  108.                 break;  
  109.         }  
  110.     }  
  111.     else  
  112.     {  
  113.         intR = R;  
  114.         intG = G;  
  115.         intB = B;  
  116.     }  
  117.     if (sValue)  
  118.     {  
  119.         if (sValue > 0)  
  120.         {  
  121.             sValue = sValue + S >= 255? S: 255 - sValue;  
  122.             sValue = 65025 / sValue - 255;  
  123.         }  
  124.         intR += ((intR - L) * sValue / 255);  
  125.         intG += ((intG - L) * sValue / 255);  
  126.         intB += ((intB - L) * sValue / 255);  
  127.         CheckRGB(intR);  
  128.         CheckRGB(intG);  
  129.         CheckRGB(intB);  
  130.     }  
  131.     AssignRGB(R, G, B, intR, intG, intB);  
  132. }  
  133.   
  134. void GdipHSBAdjustment(Bitmap *Bmp, int hValue, int sValue, int bValue)  
  135. {  
  136.     sValue = sValue * 255 / 100;  
  137.     bValue = bValue * 255 / 100;  
  138.     BitmapData data;  
  139.     Rect r(0, 0, Bmp->GetWidth(), Bmp->GetHeight());  
  140.     Bmp->LockBits(&r, ImageLockModeRead | ImageLockModeWrite, PixelFormat32bppARGB, &data);  
  141.     try  
  142.     {  
  143.         int offset = data.Stride - data.Width * 4;  
  144.         unsigned char *p = (unsigned char*)data.Scan0;  
  145.         for (int y = 0; y < data.Height; y ++, p += offset)  
  146.             for (int x = 0; x < data.Width; x ++, p += 4)  
  147.             {  
  148.                 if (sValue > 0 && bValue)  
  149.                     SetBright(p[2], p[1], p[0], bValue);  
  150.                 SetHueAndSaturation(p[2], p[1], p[0], hValue, sValue);  
  151.                 if (bValue && sValue <= 0)  
  152.                     SetBright(p[2], p[1], p[0], bValue);  
  153.             }  
  154.   
  155.     }  
  156.     __finally  
  157.     {  
  158.         Bmp->UnlockBits(&data);  
  159.     }  
  160. }  
  

BCB6界面头文件:

  1. //---------------------------------------------------------------------------  
  2.   
  3. #ifndef mainH  
  4. #define mainH  
  5. //---------------------------------------------------------------------------  
  6. #include <Classes.hpp>  
  7. #include <Controls.hpp>  
  8. #include <StdCtrls.hpp>  
  9. #include <Forms.hpp>  
  10. #include <ComCtrls.hpp>  
  11. #include <ExtCtrls.hpp>  
  12. #include "RgbHsb.h"  
  13. //---------------------------------------------------------------------------  
  14. class TForm1 : public TForm  
  15. {  
  16. __published:    // IDE-managed Components  
  17.     TButton *Button1;  
  18.     TLabel *Label1;  
  19.     TLabel *Label2;  
  20.     TLabel *Label3;  
  21.     TTrackBar *HBar;  
  22.     TTrackBar *SBar;  
  23.     TTrackBar *BBar;  
  24.     TEdit *HEdit;  
  25.     TEdit *SEdit;  
  26.     TEdit *BEdit;  
  27.     TPaintBox *PaintBox1;  
  28.     void __fastcall PaintBox1Paint(TObject *Sender);  
  29.     void __fastcall HEditKeyPress(TObject *Sender, char &Key);  
  30.     void __fastcall HEditChange(TObject *Sender);  
  31.     void __fastcall HBarChange(TObject *Sender);  
  32.     void __fastcall SBarChange(TObject *Sender);  
  33.     void __fastcall BBarChange(TObject *Sender);  
  34.     void __fastcall Button1Click(TObject *Sender);  
  35. private:    // User declarations  
  36. public:     // User declarations  
  37.     __fastcall TForm1(TComponent* Owner);  
  38.     __fastcall ~TForm1(void);  
  39. };  
  40. //---------------------------------------------------------------------------  
  41. extern PACKAGE TForm1 *Form1;  
  42. //---------------------------------------------------------------------------  
  43. #endif  

BCB6界面代码文件:

  1. //---------------------------------------------------------------------------  
  2.   
  3. #include <vcl.h>  
  4. #pragma hdrstop  
  5.   
  6. #include "main.h"  
  7. #include <stdlib.h>  
  8. //---------------------------------------------------------------------------  
  9. #pragma package(smart_init)  
  10. #pragma resource "*.dfm"  
  11. TForm1 *Form1;  
  12.   
  13. ULONG gdiplusToken;  
  14. Bitmap *Bmp, *tmpBmp;  
  15. Gdiplus::Rect r;  
  16. bool lock;  
  17.   
  18. //---------------------------------------------------------------------------  
  19. __fastcall TForm1::TForm1(TComponent* Owner)  
  20.     : TForm(Owner)  
  21. {  
  22.     Gdiplus::GdiplusStartupInput gdiplusStartupInput;  
  23.     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);  
  24.     Bmp = new Bitmap(WideString("100_0349.jpg"/*"d://100_1.jpg"*/));  
  25.     r = Gdiplus::Rect(0, 0, Bmp->GetWidth(), Bmp->GetHeight());  
  26.     tmpBmp = Bmp->Clone(r, PixelFormat24bppRGB);  
  27.     DoubleBuffered = true;  
  28.     lock = false;  
  29. }  
  30. __fastcall TForm1::~TForm1(void)  
  31. {  
  32.     delete tmpBmp;  
  33.     delete Bmp;  
  34.     GdiplusShutdown(gdiplusToken);  
  35. }  
  36. //---------------------------------------------------------------------------  
  37.   
  38.   
  39. void __fastcall TForm1::PaintBox1Paint(TObject *Sender)  
  40. {  
  41.     Gdiplus::Graphics g(PaintBox1->Canvas->Handle);  
  42.     g.DrawImage(tmpBmp, r);  
  43.     g.TranslateTransform(0, r.Height);  
  44.     g.DrawImage(Bmp, r);  
  45. }  
  46. //---------------------------------------------------------------------------  
  47.   
  48. void __fastcall TForm1::HEditKeyPress(TObject *Sender, char &Key)  
  49. {  
  50.     if (Key >= 32 && (Key < 48 || Key > 57))  
  51.         Key = 0;  
  52. }  
  53. //---------------------------------------------------------------------------  
  54.   
  55. void __fastcall TForm1::HEditChange(TObject *Sender)  
  56. {  
  57.     lock = true;  
  58.     if (((TEdit*)Sender)->Text.Length() == 0)  
  59.         ((TEdit*)Sender)->Text = "0";  
  60.     switch (((TEdit*)Sender)->Tag)  
  61.     {  
  62.         case 0: HBar->Position = HEdit->Text.ToInt();  
  63.         break;  
  64.         case 1: SBar->Position = SEdit->Text.ToInt();  
  65.         break;  
  66.         case 2: BBar->Position = BEdit->Text.ToInt();  
  67.         break;  
  68.     }  
  69.     lock = false;  
  70.     delete tmpBmp;  
  71.     tmpBmp = Bmp->Clone(r, PixelFormat24bppRGB);  
  72.     if (HBar->Position || SBar->Position || BBar->Position)  
  73.         GdipHSBAdjustment(tmpBmp, HBar->Position, SBar->Position, BBar->Position);  
  74.     PaintBox1->Invalidate();  
  75. }  
  76. //---------------------------------------------------------------------------  
  77.   
  78. void __fastcall TForm1::HBarChange(TObject *Sender)  
  79. {  
  80.     if (!lock)  
  81.         HEdit->Text = HBar->Position;  
  82. }  
  83. //---------------------------------------------------------------------------  
  84.   
  85. void __fastcall TForm1::SBarChange(TObject *Sender)  
  86. {  
  87.     if (!lock)  
  88.         SEdit->Text = SBar->Position;  
  89. }  
  90. //---------------------------------------------------------------------------  
  91.   
  92. void __fastcall TForm1::BBarChange(TObject *Sender)  
  93. {  
  94.     if (!lock)  
  95.         BEdit->Text = BBar->Position;  
  96. }  
  97. //---------------------------------------------------------------------------  
  98.   
  99. void __fastcall TForm1::Button1Click(TObject *Sender)  
  100. {  
  101.     HBar->Position = 0;  
  102.     SBar->Position = 0;  
  103.     BBar->Position = 0;  
  104. }  
  105. //---------------------------------------------------------------------------  

界面截图:

上面的代码没作多的优化,速度不是很理想,下面是一段插入汇编码,速度比前面的纯C++代码快很多倍:

  1. void _SetBrightness(BitmapData* data, long value)  
  2. {  
  3.     __asm  
  4.     {  
  5. //      push    esi  
  6. //      push    edi  
  7. //      push    ebx  
  8.   
  9.         mov     eax, data  
  10.         mov     edi, [eax + 16]  
  11.         mov     esi, [eax + 4]  
  12.         imul    esi, [eax]  
  13.         mov     edx, value  
  14.         cld  
  15.     PixelLoop:  
  16.         mov     ecx, 3  
  17.     RGBLoop:  
  18.         movzx   eax, [edi]  
  19.         mov     ebx, eax  
  20.         test    edx, edx  
  21.         js      Label1  
  22.         neg     eax  
  23.         add     eax, 255  
  24.     Label1:  
  25.         imul    eax, edx  
  26.         sar     eax, 8  
  27.         add     eax, ebx  
  28.         jns     Label2  
  29.         xor     eax, eax  
  30.         jmp     Label3  
  31.     Label2:  
  32.         cmp     eax, 255  
  33.         jle     Label3  
  34.         mov     eax, 255  
  35.     Label3:  
  36.         stosb  
  37.         loop    RGBLoop  
  38.         inc     edi  
  39.         dec     esi  
  40.         jnz     PixelLoop  
  41.   
  42. //      pop     ebx  
  43. //      pop     edi  
  44. //      pop     esi  
  45.     }  
  46. }  
  47.   
  48. void _HueAndSaturation(BitmapData* data, long hValue, long sValue)  
  49. {  
  50.     long I, S, delta;  
  51.   
  52.     __asm  
  53.     {  
  54. //      push    esi  
  55. //      push    edi  
  56. //      push    ebx  
  57.         mov     eax, data  
  58.         mov     edi, [eax + 16] // edi = Data.Scan0  
  59.         mov     ecx, [eax + 4]  
  60.         imul    ecx, [eax]  
  61.         mov     I, ecx          // I = Data.Width * Data.Height  
  62.         cld  
  63.     PixelLoop:                  // for (I --; I >= 0; I --)  
  64.         dec     I               // {  
  65.         js      end  
  66.         movzx   ecx, [edi + 2]  //   ecx = rgbMax  
  67.         movzx   ebx, [edi + 1]  
  68.         movzx   esi, [edi]  
  69.         cmp     ecx, ebx        //   esi = rgbMin  
  70.         jge     SumHsl1  
  71.         xchg    ecx, ebx  
  72.     SumHsl1:  
  73.         cmp     ecx, esi  
  74.         jge     SumHsl2  
  75.         xchg    ecx, esi  
  76.     SumHsl2:  
  77.         cmp     esi, ebx  
  78.         jle     SumHsl3  
  79.         mov     esi, ebx  
  80.     SumHsl3:  
  81.         mov     eax, ecx        //   delta = rgbMax - rgbMin  
  82.         sub     eax, esi        //   if (delta == 0)  
  83.         jnz     SumHsl4         //   {  
  84.         add     edi, 4          //     edi += 4  
  85.         jmp     PixelLoop       //     continue  
  86.     SumHsl4:  
  87.         mov     delta, eax      //   }  
  88.         add     esi, ecx  
  89.         mov     ebx, esi        //   ebx = rgbMax + rgbMin  
  90.         shr     esi, 1          //   esi = L = (rgbMax + rgbMin) / 2  
  91.         cmp     esi, 128  
  92.         jl      SumHsl5  
  93.         neg     ebx             //   if (L >= 128) ebx = 510 - ebx  
  94.         add     ebx, 510  
  95.     SumHsl5:  
  96.         imul    eax, 255        //   eax = S = delta * 255 / ebx  
  97.         cdq  
  98.         div     ebx               
  99.         cmp     hValue, 0  
  100.         je      Label1  
  101.   
  102.         push    esi             //   if (hValue != 0) Sum Hue  
  103.         push    eax  
  104.         mov     S, eax  
  105.         cmp     cl, [edi + 2]  
  106.         jne     SumHsl6  
  107.         movzx   eax, [edi + 1]  //   if (R == rgbMax) eax = G - B; ebx = 0  
  108.         movzx   edx, [edi]  
  109.         xor     ebx, ebx  
  110.         jmp     SumHsl8  
  111.     SumHsl6:  
  112.         cmp     cl, [edi + 1]  
  113.         jne     SumHsl7  
  114.         movzx   eax, [edi]      //   if (G == rgbMax) eax = B - R; ebx = 120  
  115.         movzx   edx, [edi + 2]  
  116.         mov     ebx, 120  
  117.         jmp     SumHsl8  
  118.     SumHsl7:  
  119.         movzx   eax, [edi + 2]  //   if (B == rgbMax) eax = R - G; ebx = 240  
  120.         movzx   edx, [edi + 1]  
  121.         mov     ebx, 240  
  122.     SumHsl8:  
  123.         sub     eax, edx  
  124.         imul    eax, 60         //   H = ebx + eax * 60 / delta  
  125.         cdq  
  126.         idiv    dword ptr delta  
  127.         add     eax, ebx  
  128.         add     eax, hValue     //   newH = H + hValue  
  129.         jns     SumHsl10        //   0 <= newH < 360  
  130.         add     eax, 360  
  131.     SumHsl10:  
  132.         cmp     eax, 360  
  133.         jl      SumHsl11  
  134.         sub     eax, 360  
  135.     SumHsl11:  
  136.         mov     ebx, 60  
  137.         cdq                     //   eax = newH / 60  (hue index)  
  138.         div     ebx             //   edx = newH % 60  (hue extra)  
  139.         test    eax, 1  
  140.         jz      SumHsl12  
  141.         neg     edx             //   if (eax & 1) edx = 60 - edx  
  142.         add     edx, 60  
  143.     SumHsl12:  
  144.         push    eax             //   Save hue index  
  145.         mov     eax, edx  
  146.         imul    eax, 255  
  147.         add     eax, 30  
  148.         mov     ebx, 60  
  149.         cdq  
  150.         idiv    ebx  
  151.         mov     edx, eax        //   extra = edx * 255 / 60  
  152.         mov     ebx, 255  
  153.         sub     ebx, S  
  154.         sub     eax, 128  
  155.         imul    eax, ebx  
  156.         sar     eax, 8  
  157.         sub     edx, eax        //   rgbCenter = extra -  
  158.         mov     eax, edx        //     (rxtra - 128) * (255 - S) / 255  
  159.         sub     esi, 128        //   L -= 128  
  160.         js      SumHsl13        //   eax = L < 0? rgbCenter : 255 - rgbCenter  
  161.         neg     eax  
  162.         add     eax, 255  
  163.     SumHsl13:  
  164.         imul    eax, esi  
  165.         js      SumHsl14  
  166.         add     eax, 64  
  167.     SumHsl14:  
  168.         sar     eax, 7  
  169.         add     edx, eax        //  rgbCenter = rgbCenter + eax * L / 128  
  170.         jns     SumHsl15  
  171.         xor     edx, edx  
  172.         jmp     SumHsl16  
  173.     SumHsl15:  
  174.         cmp     edx, 255  
  175.         jle     SumHsl16  
  176.         mov     edx, 255  
  177.     SumHsl16:  
  178.         pop     eax             //   reset hue index  
  179.         mov     ebx, ecx        //   ecx = rgbMax, edx = rgbCenter  
  180.         sub     ebx, delta      //   ebx = rgbMin = rgbMax - delta  
  181.         test    eax, eax        //   switch (hue index)  
  182.         jz      H60             //   {  
  183.     H120:                       //     case 1(60 - 119):  
  184.         cmp     eax, 1          //       red   = rgbCenter  
  185.         jne     H180            //       green = rgbMax  
  186.         xchg    ecx, edx        //       blue  = rgbMin  
  187.         jmp     H60             //       break  
  188.     H180:                       //     case 2(120 - 179):  
  189.         cmp     eax, 2          //       red   = rgbMin  
  190.         jne     H240            //       green = rgbMax  
  191.         xchg    ecx, ebx        //       blue  = rgbCenter  
  192.         xchg    edx, ebx          
  193.         jmp     H60             //       break  
  194.     H240:                       //     case 3(180 - 239):  
  195.         cmp     eax, 3          //       red   = rgbMin  
  196.         jne     H300            //       green = rgbCenter  
  197.         xchg    ecx, ebx        //       blue  = rgbMax  
  198.         jmp     H60             //       break  
  199.     H300:                       //     case 4(240 - 299):  
  200.         cmp     eax, 4          //       red   = rgbCenter  
  201.         jne     H360            //       green = rgbMin  
  202.         xchg    edx, ebx        //       blue  = rgbMax  
  203.         xchg    ecx, ebx  
  204.         jmp     H60             //       break  
  205.     H360:                       //     case 5:(300 - 359)  
  206.         xchg    edx, ebx        //       red=rgbMax,green=rgbMin,blue=rgbCenter  
  207.     H60:                        //       break  
  208.         mov     [edi], bl       //     default:  
  209.         mov     [edi + 1], dl   //       red=rgbMax,green=rgbCenter,blue=rgbmin  
  210.         mov     [edi + 2], cl   //   }  
  211.   
  212.         pop     eax  
  213.         pop     esi  
  214.         cmp     dword ptr sValue, 0  
  215.         jnz     Label1          //   if (sValue == 0){  
  216.         add     edi, 4          //     edi += 4, continue  
  217.         jmp     PixelLoop       //   }  
  218.     Label1:  
  219.         mov     ebx, sValue     //   ebx = sValue  
  220.         test    ebx, ebx        //   if (ebx > 0)  
  221.         js      Label10         //   {  
  222.         add     bl, al  
  223.         jnc     Label6          //     if (ebx + S >= 255)  
  224.         mov     ebx, eax        //       ebx = S  
  225.         jmp     Label7  
  226.     Label6:  
  227.         mov     ebx, 255  
  228.         sub     ebx, sValue     //     else ebx = 255 - sValue  
  229.     Label7:  
  230.         mov     eax, 65025      //     ebx = 65025 / ebx - 255  
  231.         cdq  
  232.         div     ebx  
  233.         sub     eax, 255  
  234.         mov     ebx, eax        //   }  
  235.     Label10:  
  236.         mov     ecx, 3  
  237.     RGBLoop:                    //   for (J = 3; J > 0; J --)  
  238.         movzx   eax, [edi]      //   {  
  239.         mov     edx, eax  
  240.         sub     eax, esi        //     rgb = rgb + (rgb - L) * ebx / 255  
  241.         imul    eax, ebx  
  242.         sar     eax, 8  
  243.         add     eax, edx  
  244.         jns     Label11  
  245.         xor     eax, eax        //     if (rgb < 0) rgb = 0  
  246.         jmp     Label12  
  247.     Label11:  
  248.         cmp     eax, 255  
  249.         jle     Label12  
  250.         mov     eax, 255        //     else if (rgb > 255) rgb = 255  
  251.     Label12:  
  252.         stosb                   //     *edi ++ = rgb  
  253.         loop    RGBLoop         //   }  
  254.         inc     edi             // edi ++  
  255.         jmp     PixelLoop       // }  
  256.     end:  
  257. //      pop     ebx  
  258. //      pop     edi  
  259. //      pop     esi  
  260.     }  
  261. }  

修改前面的GdipHSBAdjustment函数:

  1. void GdipHSBAdjustment(Bitmap *Bmp, int hValue, int sValue, int bValue)  
  2. {  
  3.     sValue = sValue * 255 / 100;  
  4.     bValue = bValue * 255 / 100;  
  5.     BitmapData data;  
  6.     Rect r(0, 0, Bmp->GetWidth(), Bmp->GetHeight());  
  7.     Bmp->LockBits(&r, ImageLockModeRead | ImageLockModeWrite, PixelFormat32bppARGB, &data);  
  8.     try  
  9.     {  
  10.         if (bValue && sValue > 0)  
  11.             _SetBrightness(&data, bValue);  
  12.         if (hValue || sValue)  
  13.             _HueAndSaturation(&data, hValue, sValue);  
  14.         if (bValue && sValue <= 0)  
  15.             _SetBrightness(&data, bValue);  
  16.     }  
  17.     __finally  
  18.     {  
  19.         Bmp->UnlockBits(&data);  
  20.     }  
  21. }  

如有错误或者建议,请来信指导:maozefa@hotmail.com

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
判断程序是否在虚拟机vmware内运行
OllyDBG破解入门实例(图)_3
汇编语言的准备知识
IDA简易教程
NASM x86汇编入门指南
AT&T汇编语法格式简介
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服