获取图像的像素颜色

时间:2013-11-11 18:56:26

标签: c++ gdi+

我想获得图像像素的R,G和B值。我已经使用HDC完成了它,但现在我想用Gdi +和输入图像完成它。

到目前为止,这是我的代码:

#include <iostream>
#include <stdlib.h>
#include <windows.h>
#include "gdiplus.h"
#include "stdio.h"
#include "iostream"

using namespace Gdiplus;
using namespace std;

void main(int argc, char* argv[])
{
Bitmap* mybitmap = new("bink.bmp");
int x=0;
int y=0;
Color pixelColor;
//Color pixelcolor[1000][1000];
for ( x = 0; x < 640; x++ )
   {
      for ( y = 0; y < 480; y++ )
      {
             //Color pixelColor[x][y] = mybitmap->GetPixel(x,y);
         mybitmap->GetPixel(x,y, &pixelColor);
         cout << "Pixel color " << x << ",  " << y; "is  " << pixelColor;
         //cout << "Pixel color " << x << ",  " << y; "is  " << pixelColor[x][y];
      }
   }
}

它不起作用......你能以某种方式帮助吗?

1 个答案:

答案 0 :(得分:0)

你应该使用pixelColor.GetGreen,pixelColor.GetRed,pixelColor.GetBlue