/ Forside / Teknologi / Udvikling / C/C++ / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
C/C++
#NavnPoint
BertelBra.. 2425
pmbruun 695
Master_of.. 501
jdjespers.. 500
kyllekylle 500
Bech_bb 500
scootergr.. 300
gibson 300
molokyle 287
10  strarup 270
Indlæse en bitmap
Fra : David


Dato : 13-07-01 20:13

Hej NG: Nogen der ved hvordan man indlæser en .bmp fil så man får en
HBITMAP.
Jeg har tænkt noget i denne stil:
HBITMAP hb;
HANDLE hf=CreateFile("bitmap",GENERIC_READ,FILE_SHARE_READ.....
ReadFile(hf,of hvad så.
SU David



 
 
Rasmus Christensen (16-07-2001)
Kommentar
Fra : Rasmus Christensen


Dato : 16-07-01 09:16

Hej David

Lidt kode, som måske kan bruges:

BOOL LoadBitmapFromBMPFile( LPCTSTR szFileName, HBITMAP *phBitmap, HPALETTE
*phPalette )
{
BITMAP bm;

*phBitmap = NULL;
*phPalette = NULL;

// Use LoadImage() to get the image loaded into a DIBSection
*phBitmap = (HBITMAP)LoadImage( NULL, szFileName, IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
if( *phBitmap == NULL )
{
return FALSE;
}

// Get the color depth of the DIBSection
GetObject(*phBitmap, sizeof(BITMAP), &bm );
// If the DIBSection is 256 color or less, it has a color table
if( ( bm.bmBitsPixel * bm.bmPlanes ) <= 8 )
{
HDC hMemDC;
HBITMAP hOldBitmap;
RGBQUAD rgb[256];
LPLOGPALETTE pLogPal;
WORD i;

// Create a memory DC and select the DIBSection into it
hMemDC = CreateCompatibleDC( NULL );
hOldBitmap = (HBITMAP)SelectObject( hMemDC, *phBitmap );
// Get the DIBSection's color table
GetDIBColorTable( hMemDC, 0, 256, rgb );
// Create a palette from the color table
pLogPal = (LPLOGPALETTE)malloc( sizeof(LOGPALETTE) +
(256*sizeof(PALETTEENTRY)) );
pLogPal->palVersion = 0x300;
pLogPal->palNumEntries = 256;
for(i=0;i<256;i++)
{
pLogPal->palPalEntry[i].peRed = rgb[i].rgbRed;
pLogPal->palPalEntry[i].peGreen = rgb[i].rgbGreen;
pLogPal->palPalEntry[i].peBlue = rgb[i].rgbBlue;
pLogPal->palPalEntry[i].peFlags = 0;
}
*phPalette = CreatePalette( pLogPal );
// Clean up
free( pLogPal );
SelectObject( hMemDC, hOldBitmap );
DeleteDC( hMemDC );
}
else // It has no color table, so use a halftone palette
{
HDC hRefDC;

hRefDC = GetDC()->m_hDC;
*phPalette = CreateHalftonePalette( hRefDC );
::ReleaseDC( m_hWnd, hRefDC );
}

return TRUE;
}

/Rasmus



Søg
Reklame
Statistik
Spørgsmål : 177501
Tips : 31968
Nyheder : 719565
Indlæg : 6408522
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste