fopen打开图片文件之后如何分析得到图片具体数据

lkz1156 2015-07-25 08:08:24
如题,在用fopen打开图片文件之后,我如何得到我想要的数据,比如原图片的长和宽,位深以及通道数之类的,谢谢
...全文
297 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-07-27
  • 打赏
  • 举报
回复
仅供参考:
#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;
}
encoderlee 2015-07-26
  • 打赏
  • 举报
回复
要看图片是什么格式,如果是比较简单的bmp,可以上网查一查资料,将文件头读到指定的结构体里就能获得图片信息,如果是复杂一点的jpg等格式,就比较麻烦了,建议使用现成的库来读取,比如GDI+
dustpg 2015-07-25
  • 打赏
  • 举报
回复
如果不想知道格式细节, 只想知道解码后的数据, 可以使用WIC组件
JasonCharlesBourne 2015-07-25
  • 打赏
  • 举报
回复
我猜测不同的图片都有固定的格式吧

19,469

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧