일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- synology
- E-P1
- DFS
- LSTM
- SciPy
- dataframe
- mariadb
- install
- mean
- imread
- RNN
- CNN
- Python
- 알고리즘
- 삼성소프트웨어멤버십
- javascript
- Splunk
- keras
- pip
- GT-S80
- Series
- Numpy
- index
- pycharm
- pandas
- ipad
- SPL
- GitHub
- Lotto
- Button
Archives
- Today
- Total
잠토의 잠망경
BMPTOPNG 본문
BMP 이미지를 PNG로 변환시키는 루틴
VS 2008을 사용하여야 작동합니다. ㅡㅡ; 그지같은 VS6.0
#include#include #include #include #include #define CAPTUREBLT (DWORD)0x40000000 /* Include layered windows */ #define false 0 void CaptureScreen(); void SaveBitmap(char *szFilename,HBITMAP hBitmap); int main(void) { CaptureScreen(); LPCTSTR filename=_T("c:\\test.bmp"); LPCTSTR changefilename=_T("c:\\test01.png"); CImage myImage; myImage.Load(filename); myImage.Save(changefilename); return 0; } void CaptureScreen() { int nScreenWidth = GetSystemMetrics(SM_CXSCREEN); int nScreenHeight = GetSystemMetrics(SM_CYSCREEN); HWND hDesktopWnd = GetDesktopWindow(); HDC hDesktopDC = GetDC(hDesktopWnd); HDC hCaptureDC = CreateCompatibleDC(hDesktopDC); HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hDesktopDC, nScreenWidth, nScreenHeight); SelectObject(hCaptureDC,hCaptureBitmap); BitBlt(hCaptureDC, 0, 0, nScreenWidth, nScreenHeight, hDesktopDC,0,0,SRCCOPY|CAPTUREBLT); SaveBitmap("c:\\test.png" ,hCaptureBitmap); //Place holder - Put your code //here to save the captured image to disk ReleaseDC(hDesktopWnd,hDesktopDC); DeleteDC(hCaptureDC); DeleteObject(hCaptureBitmap); } void SaveBitmap(char *szFilename,HBITMAP hBitmap) { HDC hdc=NULL; FILE* fp=NULL; LPVOID pBuf=NULL; BITMAPINFO bmpInfo; BITMAPFILEHEADER bmpFileHeader; do{ hdc=GetDC(NULL); ZeroMemory(&bmpInfo,sizeof(BITMAPINFO)); bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); GetDIBits(hdc,hBitmap,0,0,NULL,&bmpInfo,DIB_RGB_COLORS); if(bmpInfo.bmiHeader.biSizeImage<=0) bmpInfo.bmiHeader.biSizeImage=bmpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8; if((pBuf=malloc(bmpInfo.bmiHeader.biSizeImage))==NULL) { // MessageBox(NULL,"Unable to Allocate Bitmap Memory","Error",MB_OK|MB_ICONERROR); break; } bmpInfo.bmiHeader.biCompression=BI_RGB; GetDIBits(hdc,hBitmap,0,bmpInfo.bmiHeader.biHeight,pBuf,&bmpInfo,DIB_RGB_COLORS); if((fp=fopen(szFilename,"wb"))==NULL) { // MessageBox(NULL,"Unable to Create Bitmap File","Error",MB_OK|MB_ICONERROR); break; } bmpFileHeader.bfReserved1=0; bmpFileHeader.bfReserved2=0; bmpFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmpInfo.bmiHeader.biSizeImage; bmpFileHeader.bfType='MB'; bmpFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); fwrite(&bmpFileHeader,sizeof(BITMAPFILEHEADER),1,fp); fwrite(&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp); fwrite(pBuf,bmpInfo.bmiHeader.biSizeImage,1,fp); }while(false); if(hdc) ReleaseDC(NULL,hdc); if(pBuf) free(pBuf); if(fp) fclose(fp); }
Comments