Code:
#include <iostream> #include <fstream> #include <string> #include <windows.h> #include < gdiplus.h> #pragma comment (lib, "Gdiplus.lib") using namespace Std;using namespace Gdiplus;int main () {Gdiplusstartup Input Gdiplusstartupinput; ULONG_PTR Gdiplustoken; Gdiplusstartup (&gdiplustoken, &gdiplusstartupinput, NULL); Wstring infilename (L "1.jpg"); String Outfilename ("Color.txt"); bitmap* bmp = New Bitmap (INFILENAME.C_STR ()); UINT height = bmp->getheight (); UINT width = bmp->getwidth (); cout << "width" << width << "height" << height << Endl; Color color; Ofstream Fout (Outfilename.c_str ()); for (uint y = 0; y < height; y++.) for (uint x = 0; x < width; x + +) {Bmp->getpixel ×, y, &A Mp;color); Fout << x << "," << y << ";" << (int) color. Getred () << "," << (int) color. GetgreEn () << "," << (int) color. GetBlue () << Endl; } fout.close (); Delete bmp; Gdiplusshutdown (Gdiplustoken); return 0;}
VC + + Read image RGB value