GDI+ 读取jpg图片每个像素的值

简介:     // 读取jpg图像像素rgb值.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #include #include #include #pragma comment(lib, "gdiplus.

 

 

// 读取jpg图像像素rgb值.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#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 (int y = 0; y < height; y++)
		for (int 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;
}

 

 

txt:

 


相关文章
|
7月前
|
C#
C# 图片RGB处理判断
C# 图片RGB处理判断 需要:根据一张原始图的RGB平均值和新的图片的RGB平均值的差距,来判断图中是否出现除原图中物体外的其他物体 前提:.Net framework 4.8 及以上 示例代码: 程序集:using System;using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imagin...
25 0
|
9月前
|
人工智能
将 JPEG 和 PNG 位图转换为 SVG 矢量图,可无限放大
将 JPEG 和 PNG 位图转换为 SVG 矢量图,可无限放大
207 0
|
10月前
|
JavaScript 前端开发
图片转base64、判断图片大小、图片压缩、图片上传
文章主要介绍 `js` 实现压缩上传图片转base64,其他的框架(如React、Vue、Angular)也可借此参考。**这个方法真实可用,已在实际项目中运行**。
188 0
|
机器学习/深度学习 计算机视觉
【图片操作】提取GIF的图片帧
gif是我们日常生活中常用的一种图片,它介于视频和图片之间。我们可以用图片的内存体验到一些视频的感觉。但是有时候我们会想把gif的图片全部提取出来,今天我们就来实现一下这个操作。
338 0
将RGB转换为JPG格式到内存的代码
将RGB转换为JPG格式到内存的代码
126 0
wx.chooseImage 的sizeType 拿到压缩图和原图数据
我的理解应该是:如果sizeType为:['original', 'compressed'] 时,那 tempFilePaths 就应该是返回 2个路径才对,一个是原图的路径,一个是压缩图的路径,但实际上只返回了一个路径,那请问,这个返回的路径是原图的,还是压缩图的?
174 0
wx.chooseImage 的sizeType 拿到压缩图和原图数据
|
计算机视觉
OpenCV 读写图像、读写像素、修改像素值(案例:图像反处理)
OpenCV 读写图像、读写像素、修改像素值(案例:图像反处理)
484 0
OpenCV 读写图像、读写像素、修改像素值(案例:图像反处理)
|
Python
将8位的tif图片改为png图片
将8位的tif图片改为png图片
181 0