HOWTO: Kaip naudotis LoadImage() skaityti BMP fail?

Straipsni? vertimai Straipsni? vertimai
Straipsnio ID: 158898 - Per?i?r?ti ?iame straipsnyje minimus produktus.
I?pl?sti visus | Sutraukti visus

Santrauka

LoadImage API gali b?ti naudojama pakrauti rastrinis vaizdas i? BMP fail?. Ta?iau ji negr??ina palet?s informacija. ?is straipsnis suteikia m?ginio kod? ir apra?oma, kaip nuskaityti bitmap su LoadImagepalet?s informacij?.

Daugiau informacijos

?is kodas naudoja LoadImage API kaip Rastro ?kelti ? DIBSection, ir tada sukuria palet? ir DIBSection spalv? lentel?. Jei n?ra spalv? lentel?, pustoni? palet?s yra naudojamas:
   BOOL LoadBitmapFromBMPFile( LPTSTR 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 tabl
   pLogPal = (LOGPALETTE *)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( NULL );
   *phPalette = CreateHalftonePalette( hRefDC );
   ReleaseDC( NULL, hRefDC );
   }
   return TRUE;

   }
				
?? kod? parodo, kaip naudotis LoadBitmapFromBMPFile funkcija:
   case WM_PAINT:
   {
     PAINTSTRUCT   ps;
     HBITMAP       hBitmap, hOldBitmap;
     HPALETTE      hPalette, hOldPalette;
     HDC           hDC, hMemDC;
     BITMAP        bm;

   hDC = BeginPaint( hWnd, &ps );

   if( LoadBitmapFromBMPFile( szFileName, &hBitmap, &hPalette ) )
   {
      GetObject( hBitmap, sizeof(BITMAP), &bm );
      hMemDC = CreateCompatibleDC( hDC );
      hOldBitmap = (HBITMAP)SelectObject( hMemDC, hBitmap );
      hOldPalette = SelectPalette( hDC, hPalette, FALSE );
      RealizePalette( hDC );

      BitBlt( hDC, 0, 0, bm.bmWidth, bm.bmHeight,
              hMemDC, 0, 0, SRCCOPY );

      SelectObject( hMemDC, hOldBitmap );
      DeleteObject( hBitmap );
      SelectPalette( hDC, hOldPalette, FALSE );
      DeleteObject( hPalette );
   }
   EndPaint( hWnd, &amp;ps );

   }
   break;
				

Savyb?s

Straipsnio ID: 158898 - Paskutin? per?i?ra: 2013 m. bir?elio 7 d. - Per?i?ra: 1.0
Taikoma:
  • Microsoft Win32 Application Programming Interface (programavimo aplinka), naudojant su:
    • Microsoft Windows NT Server 4.0 Standard Edition
    • Microsoft Windows NT Workstation 4.0 Developer Edition
    • Microsoft Windows 95
Rakta?od?iai: 
kbcode kbFAQ kbhowto kbmt KB158898 KbMtlt
Atliktas automatinis vertimas
SVARBU: ?is straipsnis i?verstas naudojant ?Microsoft? ma?ininio vertimo programin? ?rang? ir gali b?ti pataisytas naudojant ?Community Translation Framework? (CTF) technologij?. ?Microsoft? si?lo ma?inos i?verstus ir po to bendruomen?s suredaguotus straipsnius, taip pat ?mogaus i?verstus straipsnius siekdama suteikti prieig? prie vis? savo ?ini? baz?s straipsni? daugeliu kalb?. Ma?inos i?verstuose ir v?liau paredaguotuose straipsniuose gali b?ti ?odyno, sintaks?s ir / arba gramatikos klaid?. ?Microsoft? neatsako u? jokius netikslumus, klaidas arba ?al?, patirt? d?l neteisingo turinio vertimo arba m?s? klient? naudojimosi juo. Daugiau apie CTF ?r. http://support.microsoft.com/gp/machine-translation-corrections.
Spustel?kite ?ia, nor?dami pamatyti ?io straipsnio versij? angl? kalba: 158898

Pateikti atsiliepim?

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com