c++ - 将位图数据转换为 rgb visual c++
问题描述
我正在尝试拍摄位图图像并获取像素的 RGB 值。我目前拥有的将打开位图文件并读取像素数据:
#define _CRT_SECURE_NO_DEPRECATE
#include "findColor.h"
#include <vector>
#include <iostream>
int findColor(std::string path) {
std::vector<std::string> averageColor; //Will hold the average hex color of each image in order.
std::string currentImage;
currentImage = path + std::to_string(i) + ".btm";
FILE* f = fopen(currentImage.c_str(), "rb");
unsigned char info[54]; //Bitmap header is 54 bytes
fread(info, sizeof(unsigned char), 54, f); //reading the header
// extract image height and width from header
int width, height;
memcpy(&width, info + 18, sizeof(int));
memcpy(&height, info + 22, sizeof(int));
int heightSign = 1;
if (height < 0) {
heightSign = -1;
}
int size = 3 * width * height; //size of image in bytes. 3 bytes per pixel.
unsigned char* data = new unsigned char[size]; // allocate 3 bytes per pixel
fread(data, sizeof(unsigned char), size, f); // read the rest of the data at once
fclose(f); //close image.
for (i = 0; i < size; i += 3) //Flip the image data? It is stored as BGR flipping it to RGB?
{
unsigned char tmp = data[i-33];
data[i] = data[i + 2];
data[i + 2] = tmp;
}
return 0;
}
我真的不知道从这里去哪里。任何回应将不胜感激。
解决方案
推荐阅读
- java - 当类包含包级方法时,如何将类隐藏在接口后面?
- java - 需要登录时将服务器数据拉到 ViewModel
- django - 如何将暂存数据库复制到 Heroku 评论应用程序
- flutter - 从 DocumentReference 中获取数据
- kotlin - 有没有可能的方法来映射引用表中的外键名称?(多对多)
- wordpress - HTTP 站点在更改为 HTTPS 后停止显示来自站点的最新 RSS 提要
- javascript - Shopify 中叙事主题的幻灯片自动播放
- swift - AVPlayerItem 状态观察者 - 单元测试状态更改
- azure - 无法从 Visual Studio 2019 Web 部署到 Linux 应用服务
- firefox - 当我们在 Firefox 中禁用历史记录时会发生什么?