[英]Stb Image not loading in data correctly
我使用stb_image.h
庫,我的目標是獲取 jpg 的每個像素的 rgb 數據。 但是當我調用負載 function 時,它只給了我一堆奇怪的符號而不是實際數字。 這可能是由於圖像還是我的代碼錯了?
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
int width, height;
int comp;
const char* filename = "C:/Users/graha/source/repos/AiFirsy/Debug/rainbow.jpg";
unsigned char* data = stbi_load(
filename, &width, &height, &comp, 0);
if (data == nullptr) {
std::cerr << "ERROR: Could not load texture image file '" << filename << "'.\n";
width = height = 0;
}
cout << data[0];
}
這是圖像
output stream (在這種情況下為std::cout
)會將'char' 類型解釋為 characters 。 如果要查看數值,可以將值轉換為適當的類型。 例如:
unsigned char const value = 'c';
std::cout << value << std::endl;
std::cout << static_cast<unsigned int>(value) << std::endl;
輸出:
c
99
另外,順便說一句,您正在訪問data
,即使它是 null,我猜這不是您想要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.