Programming/MFC [JPG 파일 생성] JPG 데이터 버퍼로 이미지 파일 생성하기 푸어맨 2017. 5. 10. 15:24 typedef struct _GUI_BMP { // Bitmap File Header short bfType; // "BM"(0x424D) BitMap이라는 캐릭터형이 저장되어 있습니다. int bfSize; // 파일의 전체 크기를 표시합니다. short bfReserved1; short bfReserved2; int bfOffBits; // 실질 데이터(pixel)의 시작좌표를 OFFSET 주소를 나타냅니다. // Bitmap Image Header int biSize; // 이미지 헤더 크기(최소 40bytes) int biWidth; // 이미지 폭 int biHeight; // 이미지 높이 short biPlanes; // 현재 지원 값은 1입니다. short biBitCount; // 비트수 1,4,8,16,24,32 int biCompression; // 압축타입 : BI_RGB(0), BI_RLE8(1), BI_RLE4(2), BI_BITFIELDS(3) int biSizeImage; // 이미지 크기 int biXpelsPerMeter; // 미터당 픽셀수 x축 int biYpelsPerMeter; // 미터당 픽셀수 y축 int biClrUsed; // 실질적으로 사용될 컬러맵의 엔트리수 int biClrIMportant; // 주로 사용되는 컬러수 } GUI_BMP; int SaveJpgFile_320_240(char *rgb) { /*--------------------- 실제 파일에 기록함 --------------------------*/ const char *filename = "optic_axis.jpg"; const int bmpWidth = 320, bmpHeight = 240, bmpBit = 24; FILE *pFile = NULL; char* pBmpBuf; DWORD FileSize; FileSize = bmpWidth * bmpHeight * 3; pBmpBuf = new char[FileSize + sizeof(BITMAPINFOHEADER)]; BITMAPINFOHEADER bi; bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = bmpWidth; bi.biHeight = bmpHeight; bi.biPlanes = 1; bi.biBitCount = bmpBit; bi.biCompression = BI_RGB; bi.biSizeImage = FileSize; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; memcpy(pBmpBuf, &bi, sizeof(bi)); memcpy(pBmpBuf + sizeof(BITMAPINFOHEADER), rgb, FileSize); fopen_s(&pFile, filename, "wb"); bool bResult = false; if (pFile != NULL) { fwrite(pBmpBuf, FileSize, 1, pFile); fclose(pFile); bResult = true; } delete[] pBmpBuf; return bResult; }