VC++读取图像RGB值

简介: 代码: #include #include #include #include #include #pragma comment(lib, "gdiplus.lib")using namespace std;using namespace Gdiplus;in...


代码:

#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() 
{
    GdiplusStartupInput 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(x, y, &color);
            fout << x << "," << y << ";"
                 << (int)color.GetRed()   << ","
                 << (int)color.GetGreen() << ","
                 << (int)color.GetBlue()  << endl;
    }

    fout.close();

    delete bmp;
    GdiplusShutdown(gdiplustoken);
    return 0;
}


相关文章
|
6月前
|
C#
C# 图片RGB处理判断
C# 图片RGB处理判断 需要:根据一张原始图的RGB平均值和新的图片的RGB平均值的差距,来判断图中是否出现除原图中物体外的其他物体 前提:.Net framework 4.8 及以上 示例代码: 程序集:using System;using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imagin...
21 0
CMKY与RGB的转换
CMKY与RGB的转换
81 0
RGB转换为NV12的代码
RGB转换为NV12的代码
184 0
|
前端开发 JavaScript Java
通过canvas转换颜色为RGBA格式及性能问题
通过canvas转换颜色为RGBA格式及性能问题
通过canvas转换颜色为RGBA格式及性能问题
RGB颜色设置错误
RGB颜色设置错误
119 0
|
C#
c# 颜色RGB到HSB互相转换
原文:c# 颜色RGB到HSB互相转换 1 /// 2 /// 色相,饱和度,亮度转换成rgb值 3 /// 4 /// 5 public static float[] HSB2RGB(float[...
1997 0