cs_Mamelook
Messages postés48Date d'inscriptionjeudi 10 juillet 2003StatutMembreDernière intervention27 juillet 2008
-
7 juil. 2007 à 17:23
cs_Mamelook
Messages postés48Date d'inscriptionjeudi 10 juillet 2003StatutMembreDernière intervention27 juillet 2008
-
8 juil. 2007 à 02:40
Comment peut t-on reduire la taille d'une image BMP (HBITMAP) ? J'ai entendu parler de la fonction StretchBlt() de l'api windows, mais je voit pas comment on peut faire sa, pouvez vous m'aider ?
cs_Mamelook
Messages postés48Date d'inscriptionjeudi 10 juillet 2003StatutMembreDernière intervention27 juillet 2008 7 juil. 2007 à 19:10
Dsl mais ji arrive vraiment pas, se que je voudrai faire c'est que cette fonction (que j'ai prit sur une source de ce site [je sai plus laquel]) puissent retourner une image redimentionner :
BITMAPFILEHEADER m_BitmapFileHeader; // Données de la structure BITMAPFILEHEADER du Bitmap
PBITMAPINFOHEADER m_pBitmapInfoHeader; // Pointeur sur la structure BITMAPINFOHEADER du Bitmap
PBITMAPINFO m_pBitmapInfo; // Pointeur sur la structure BITMAPINFO du Bitmap
LPBYTE m_pBitmapData; // Pointeur sur les Data du Bitmap
HDC m_hDcBitmap; // Handle sur le hDc du Bitmap en memoire
HBITMAP m_hBitmap; // Handle sur le Bitmap
bool TakeDesktopSnapshot(void)
{
// Récupération du HWND et du HDC du bureau
HWND hWndWindow = GetDesktopWindow();
HDC hDcWindow = GetWindowDC(hWndWindow);
// On récupére les dimensions du bureau
int ScreenX = GetDeviceCaps(hDcWindow, HORZRES);
int ScreenY = GetDeviceCaps(hDcWindow, VERTRES);
// Création d'un contexte mémoire
m_hDcBitmap = CreateCompatibleDC(hDcWindow);
if(!m_hDcBitmap) return 0;
// On crée un bitmap en mémoire ayant les dimensions du bureau
HBITMAP hBitmap = CreateCompatibleBitmap(hDcWindow, ScreenX, ScreenY);
if(!hBitmap) return 0;
// On sélectionne ce bitmap dans le contexte mémoire
if(!SelectObject(m_hDcBitmap, hBitmap)) return 0;
// On effectue une copie du contexte écran vers le contexte mémoire
if(!BitBlt(m_hDcBitmap, 0, 0, ScreenX, ScreenY, hDcWindow, 0, 0, SRCCOPY)) return 0;
// Maintenant on crée la structure BITMAPINFO
BITMAP Bitmap;
WORD Couleur;
// Récupération de la structure BITMAP
if (!GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap)) return 0;
// Convertie le format de couleur
Couleur = (WORD)(Bitmap.bmPlanes * Bitmap.bmBitsPixel);
if (Couleur 1) Couleur 1;
else if (Couleur <4) Couleur 4;
else if (Couleur <8) Couleur 8;
else if (Couleur <16) Couleur 16;
else if (Couleur <24) Couleur 24;
else Couleur = 32;
// Alloue de la memoire pour la structure BITMAPINFO (Cette structure
// contient une structure BITMAPINFOHEADER et un tableau de RGBQUAD
if (Couleur != 24)
m_pBitmapInfo = (PBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * (1<< Couleur)];
// Il n'y a pas de tableau de RGBQUAD pour le format 24 bit
else
m_pBitmapInfo = (PBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
// If the bitmap is not compressed, set the BI_RGB flag.
m_pBitmapInfo->bmiHeader.biCompression = BI_RGB;
m_pBitmapInfo->bmiHeader.biSizeImage = ((m_pBitmapInfo->bmiHeader.biWidth * Couleur +31) & ~31) /8 * m_pBitmapInfo->bmiHeader.biHeight;
// Set biClrImportant to 0, indicating that all of the
// device colors are important.
m_pBitmapInfo->bmiHeader.biClrImportant = 0;
m_pBitmapData = new BYTE[m_pBitmapInfoHeader->biSizeImage];
if (!m_pBitmapData) return 0;
// Retrieve the color table (RGBQUAD array) and the bits
// (array of palette indices) from the DIB.
if (!GetDIBits(m_hDcBitmap, hBitmap, 0, (WORD) m_pBitmapInfoHeader->biHeight, m_pBitmapData, m_pBitmapInfo, DIB_RGB_COLORS)) return 0;
// Compute the size of the entire file.
m_BitmapFileHeader.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + m_pBitmapInfoHeader->biSize + m_pBitmapInfoHeader->biClrUsed * sizeof(RGBQUAD) + m_pBitmapInfoHeader->biSizeImage);
m_BitmapFileHeader.bfReserved1 = 0;
m_BitmapFileHeader.bfReserved2 = 0;
// Compute the offset to the array of color indices.
m_BitmapFileHeader.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + m_pBitmapInfoHeader->biSize + m_pBitmapInfoHeader->biClrUsed * sizeof (RGBQUAD);
luhtor
Messages postés2023Date d'inscriptionmardi 24 septembre 2002StatutMembreDernière intervention28 juillet 20086 7 juil. 2007 à 20:47
Pk tu tiens absolument à bouffer du bmp ? Ya plein de petites librairies (ou grosse) pour lire un bmp. Tu en obtiens alors facilement le buffer de données. Tu le redimensionnes et tu utilises de nouveau la librairie pour sauvegarder le nouveau bmp.
cs_Mamelook
Messages postés48Date d'inscriptionjeudi 10 juillet 2003StatutMembreDernière intervention27 juillet 2008 7 juil. 2007 à 21:12
Et bien, les librairy que j'ai vue sont bien trop lourde (plus de 100ko), j'ai un cahier des charges a respecter, donc pour l'instan c'est a bannir ...
Vous n’avez pas trouvé la réponse que vous recherchez ?
SAKingdom
Messages postés3212Date d'inscriptionlundi 7 novembre 2005StatutMembreDernière intervention16 février 200915 7 juil. 2007 à 22:07
LoadImage
SelectObject du HBITMAP retourné sur un DC mémoire créé avec CreateCompatibleDC
StretchBlt sur DC principal récupéré avec GetDC et le tour est joué.
Voici un exemple complet. L'image IMAGE_NAME est redimensionné selon les dimensions de la fenêtre: