Convert Bitmap to Csv with c++

#include <Windows.h>
#include <stdio.h>
#include <assert.h>
#include <fstream>
using namespace std;
const int TEXX=512;
const int TEXY=512;
unsigned char texturedatapointer[TEXX*TEXY*4];
void LoadTextureData(TCHAR* _filename){
    wprintf(L"%s",_filename);
    HANDLE handle;
    DWORD temp=0;
    BITMAPFILEHEADER bitmapFileHeader;
    BITMAPINFOHEADER bitmapInfoHeader;
    handle = CreateFile(_filename,GENERIC_READ,FILE_SHARE_READ, NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL );
 
    if(handle==INVALID_HANDLE_VALUE || handle==NULL){assert(!"だめ");}
    ReadFile(handle,&bitmapFileHeader,sizeof(BITMAPFILEHEADER),&temp,NULL);
    if ( temp!=sizeof(BITMAPFILEHEADER) || bitmapFileHeader.bfType!=0x4D42 )
    {
        CloseHandle(handle);
        assert(!"bmp形式じゃありません");
    }
    ReadFile(handle,&bitmapInfoHeader,sizeof(BITMAPINFOHEADER),&temp,NULL);
 
      ReadFile(handle,texturedatapointer,TEXX*TEXY*4,&temp,NULL);
    CloseHandle(handle);
 
}
void WriteTextData(const char* _filename){
    ofstream ofs;
    ofs.open(_filename);
 
        for(int y=0;y<TEXY;y++){
            for(int x=0;x<TEXX;x++){
            ofs<<(int)texturedatapointer[(y*TEXX+x)*4+1]<<",";
        }
        ofs<<endl;
    }
    ofs.close();
}
void main(){
    LoadTextureData("seed.bmp");
    WriteTextData("bmp.csv");
}
en.gif en
ja.gif ja


edit
サポートサイト Wikidot.com