Accueil > > > BMP FILE DEPUIS HDC EN PUR API (WIN32)
BMP FILE DEPUIS HDC EN PUR API (WIN32)
Information sur la source
Description
HdcToBmpFile(HDC hdc, char *pszflname) fait tout le travail. Aucune dll externe necessaire. CPP et EXE test(capture d'ecran) dans le zip.
Source
- int __stdcall HdcToBmpFile(HDC hdc, char *pszflname)
- {
- HDC memdc;
- HANDLE hfl;
- DWORD dwBytes, dwWidth, dwHeight, dwNumColors, dwBPP, ColorSize;
- void *pBits;
- HBITMAP hbmp;
- BITMAPFILEHEADER fileheader;
- BITMAPINFOHEADER infoheader;
- RGBQUAD colors[256];
- BITMAPINFO bmpinfo;
- HGDIOBJ hret;
- dwWidth = GetDeviceCaps(hdc, HORZRES);
- dwHeight = GetDeviceCaps(hdc, VERTRES);
- dwBPP = GetDeviceCaps(hdc, BITSPIXEL);
- if(dwBPP <= 8) dwNumColors = 256;
- else dwNumColors = 0;
- if(!(memdc = CreateCompatibleDC(hdc))) return 0;
- bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bmpinfo.bmiHeader.biWidth = dwWidth;
- bmpinfo.bmiHeader.biHeight = dwHeight;
- bmpinfo.bmiHeader.biPlanes = 1;
- bmpinfo.bmiHeader.biBitCount = (WORD) dwBPP;
- bmpinfo.bmiHeader.biCompression = BI_RGB;
- bmpinfo.bmiHeader.biSizeImage = 0;
- bmpinfo.bmiHeader.biXPelsPerMeter = 0;
- bmpinfo.bmiHeader.biYPelsPerMeter = 0;
- bmpinfo.bmiHeader.biClrUsed = dwNumColors;
- bmpinfo.bmiHeader.biClrImportant = dwNumColors;
- hbmp = CreateDIBSection(hdc, &bmpinfo, DIB_PAL_COLORS, &pBits, NULL, 0);
- if(!hbmp) goto errato;
- hret = SelectObject(memdc, hbmp);
- if(!hret || (hret == HGDI_ERROR)) goto errato;
- if(!BitBlt(memdc, 0, 0, dwWidth, dwHeight, hdc, 0, 0, SRCCOPY)) goto errato;
- if(dwNumColors) dwNumColors = GetDIBColorTable(memdc, 0, dwNumColors, colors);
- fileheader.bfType = 0x4D42;
- ColorSize = dwNumColors * sizeof(RGBQUAD);
- fileheader.bfSize = ((dwWidth*dwHeight*dwBPP) >> 3)+ColorSize+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
- fileheader.bfReserved1 = fileheader.bfReserved2 = 0;
- fileheader.bfOffBits = ColorSize+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
- infoheader.biSize = sizeof(BITMAPINFOHEADER);
- infoheader.biWidth = dwWidth;
- infoheader.biHeight = dwHeight;
- infoheader.biPlanes = 1;
- infoheader.biBitCount = (WORD) dwBPP;
- infoheader.biCompression = BI_RGB;
- infoheader.biSizeImage = infoheader.biClrImportant = 0;
- infoheader.biXPelsPerMeter = infoheader.biYPelsPerMeter = 0;
- infoheader.biClrUsed = dwNumColors;
- hfl = CreateFile(pszflname,GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
- if(hfl == INVALID_HANDLE_VALUE) {DeleteObject(hbmp); goto errato;}
- WriteFile(hfl, &fileheader, sizeof(BITMAPFILEHEADER), &dwBytes, 0);
- WriteFile(hfl, &infoheader, sizeof(BITMAPINFOHEADER), &dwBytes, 0);
- if(!dwNumColors) WriteFile(hfl, colors, ColorSize, &dwBytes, 0);
- ColorSize = (dwWidth*dwHeight*dwBPP) >> 3;
- WriteFile(hfl, pBits, ColorSize, &dwBytes, 0);
- CloseHandle(hfl);
- DeleteObject(hbmp);
- DeleteDC(memdc);
- return 1;
- errato:
- DeleteDC(memdc); return 0;
- }
int __stdcall HdcToBmpFile(HDC hdc, char *pszflname)
{
HDC memdc;
HANDLE hfl;
DWORD dwBytes, dwWidth, dwHeight, dwNumColors, dwBPP, ColorSize;
void *pBits;
HBITMAP hbmp;
BITMAPFILEHEADER fileheader;
BITMAPINFOHEADER infoheader;
RGBQUAD colors[256];
BITMAPINFO bmpinfo;
HGDIOBJ hret;
dwWidth = GetDeviceCaps(hdc, HORZRES);
dwHeight = GetDeviceCaps(hdc, VERTRES);
dwBPP = GetDeviceCaps(hdc, BITSPIXEL);
if(dwBPP <= 8) dwNumColors = 256;
else dwNumColors = 0;
if(!(memdc = CreateCompatibleDC(hdc))) return 0;
bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpinfo.bmiHeader.biWidth = dwWidth;
bmpinfo.bmiHeader.biHeight = dwHeight;
bmpinfo.bmiHeader.biPlanes = 1;
bmpinfo.bmiHeader.biBitCount = (WORD) dwBPP;
bmpinfo.bmiHeader.biCompression = BI_RGB;
bmpinfo.bmiHeader.biSizeImage = 0;
bmpinfo.bmiHeader.biXPelsPerMeter = 0;
bmpinfo.bmiHeader.biYPelsPerMeter = 0;
bmpinfo.bmiHeader.biClrUsed = dwNumColors;
bmpinfo.bmiHeader.biClrImportant = dwNumColors;
hbmp = CreateDIBSection(hdc, &bmpinfo, DIB_PAL_COLORS, &pBits, NULL, 0);
if(!hbmp) goto errato;
hret = SelectObject(memdc, hbmp);
if(!hret || (hret == HGDI_ERROR)) goto errato;
if(!BitBlt(memdc, 0, 0, dwWidth, dwHeight, hdc, 0, 0, SRCCOPY)) goto errato;
if(dwNumColors) dwNumColors = GetDIBColorTable(memdc, 0, dwNumColors, colors);
fileheader.bfType = 0x4D42;
ColorSize = dwNumColors * sizeof(RGBQUAD);
fileheader.bfSize = ((dwWidth*dwHeight*dwBPP) >> 3)+ColorSize+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
fileheader.bfReserved1 = fileheader.bfReserved2 = 0;
fileheader.bfOffBits = ColorSize+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
infoheader.biSize = sizeof(BITMAPINFOHEADER);
infoheader.biWidth = dwWidth;
infoheader.biHeight = dwHeight;
infoheader.biPlanes = 1;
infoheader.biBitCount = (WORD) dwBPP;
infoheader.biCompression = BI_RGB;
infoheader.biSizeImage = infoheader.biClrImportant = 0;
infoheader.biXPelsPerMeter = infoheader.biYPelsPerMeter = 0;
infoheader.biClrUsed = dwNumColors;
hfl = CreateFile(pszflname,GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
if(hfl == INVALID_HANDLE_VALUE) {DeleteObject(hbmp); goto errato;}
WriteFile(hfl, &fileheader, sizeof(BITMAPFILEHEADER), &dwBytes, 0);
WriteFile(hfl, &infoheader, sizeof(BITMAPINFOHEADER), &dwBytes, 0);
if(!dwNumColors) WriteFile(hfl, colors, ColorSize, &dwBytes, 0);
ColorSize = (dwWidth*dwHeight*dwBPP) >> 3;
WriteFile(hfl, pBits, ColorSize, &dwBytes, 0);
CloseHandle(hfl);
DeleteObject(hbmp);
DeleteDC(memdc);
return 1;
errato:
DeleteDC(memdc); return 0;
}
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Modification de fichier BMP [ par titio ]
Bonjour,Je souhaite afficher des images bmp, tout en ayant la possibilité de modifier ce fichier. Pour cela, je le charge en memoire, et souhaite
Hwnd [ par T_Mehdi ]
salut a tous .bon j'ai realiser une fonction qui permet douvrir des fichier bmp et les affichier sur un hwnd preci.le prob est que quand je reduit ou
Pixel vide [ par sabran ]
Salut, Je veux lire la valeur RGB d'un pixel avec GetDIBits. J'ai pris un code que j'ai vu plusieurs fois sur le forum. Tout marche sauf quand je veux
Redimensionnement image Borland C++ [ par jfouquet ]
Bonjour, Je travaille actuellement sous Borland C++ 5. Je suis amené à afficher une image (jpeg,bmp,ico…) dans un TImage bon ça
need help_API - debutant. [ par JimyRyan ]
j'ai cree un progamme qui affiche une image (stoquee dans un fichier .bmp), et une phrase (lu a partir d'un fichier TXT), j'ai deux problemes : une fo
Mes bitmap se barrent [ par oceax ]
Salut !Voila j'ai fais une boite de dialogue en Win32 et j'ai inséré une bmp à l'aide de LoadBitmap() et pis DrawState(). Ma bitmap s'a
Convertion d'un bitmap 8 bits en un bitmal 24 bits [ par SauCisS ]
Bonjour, J'ai parcouru ce forum pour chercher ma réponse, mais sans succès. Alors voici mon problème : Comment à partir d'une
redimentionnement d'image, aidez-moi svp [ par sousou_one ]
salut à tous,je veux construire une bitmap par copie d'une région d'une bitmap source, je dois prendre les nouvelles dimensions en séle
Capture écran dans le menu contextuel [ par lunnatick ]
Bonjour à tous, je recherche un logiciel de capture d’écran (gratuit de préférence) qui ajoute dans le menu contextuel de Win
HBTMAP de l'écran [ par clem0338 ]
Bonjour, J'essaie de récupérer un Handle du bitmap de l'écran HDC hDC = GetDC( 0 ); // DC de l'écran HBITMAP hBm; GetObject( hD
|
Derniers Blogs
TECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PCTECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PC par ROMELARD Fabrice
Speakers: Thierry Rapatout, Antoine Petit et Xavier Trebbia Cette session entre dans le cadre des RDV Décideurs des TechDays 2012, elle est liée à la consumérisation de l'IT et la mise en place du "DeskTop as a Service" dans de plus en ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLETECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLE par ROMELARD Fabrice
Speakers: Julien Marechal, Gautier Confiant, Sébastien MEYER La session débute par le positionnement de la solution System Center par rapport aux concepts d'organisation ITIL. Le portail du catalogue de se...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : PLEINIèRE SECOND JOURTECHDAYS PARIS 2012 : PLEINIèRE SECOND JOUR par ROMELARD Fabrice
Après une première journée dédiée aux développeurs, cette seconde journée est dédiée au monde des entreprises et de ses applications. Ainsi, cette pleinière est dédiée à faire un 360 de l'évolution des applications Business aux demandes ac...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : RETOUR D'EXPéRIENCE SUR LA MISE EN PLACE D'UN CLOUD PRIVéTECHDAYS PARIS 2012 : RETOUR D'EXPéRIENCE SUR LA MISE EN PLACE D'UN CLOUD PRIVé par ROMELARD Fabrice
Speaker : Guillaume Rochette Cette session est dédiée à fournir le retour sur la mise en place d'un cloud privé (IaaS) par Osiatis pour son compte ou celui de ses clients. Ce projet s'est déroulé sur 4 mois et a permis de faire évoluer...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYSTECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYS par ROMELARD Fabrice
Speakers : Lionel Limozin et Alain Marty La session commence par une découverte de SharePoint à travers la mise en place d'un environnement SharePoint pour la gestion des Sessions animées par BeWise. Le besoin est très ba...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
AUMLAUML par sassion
Cliquez pour lire la suite par sassion
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|