🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.ms-windows.programacion
Article #76

RE: cargar BMP desde archivo con Visual C++

#76
From: Crist�bal Tello
Date: Fri, 24 Aug 2001 21:36
104 lines
3412 bytes
Hola Carlos, prueba con esto...

Archivo Dib.hpp
ifndef DIB_HPP
#define DIB_HPP

class cDib {
 BITMAPINFO *pInfo;
 BYTE  *pPixels;
 int GetPalEntries(BITMAPINFOHEADER &);
 BYTE *GetPixelPtr(){return pPixels;};
 BITMAPINFO *GetHeaderPtr(){return pInfo;};
 int GetWidth(){return pInfo->bmiHeader.biWidth;};
 int GetHeight(){return pInfo->bmiHeader.biHeight;};

public:
 cDib();
 ~cDib();
 bool Load(const char *);
 void Draw(CDC *, CRect);

};

#endif

Archivo Dib.cpp
#include "stdafx.h"
#include "Dib.hpp"

cDib::cDib()
{
 pInfo=0;
 pPixels=0;
}

cDib::~cDib()
{
 if(pInfo) delete [] pInfo;
 if(pPixels) delete [] pPixels;
}

bool cDib::Load(const char *psName)
{
 CFile file;
 file.Open(psName, CFile::modeRead);

 if(pInfo) delete [] pInfo;
 if(pPixels) delete [] pPixels;
 pInfo=0;
 pPixels=0;
 BITMAPFILEHEADER FileHeader;
 file.Read(&FileHeader, sizeof(FileHeader));
 if(FileHeader.bfType!=0x4D42)
  return false;
 BITMAPINFOHEADER InfoHeader;
 file.Read(&InfoHeader, sizeof(InfoHeader));
 if(InfoHeader.biSize!=sizeof(InfoHeader))
  return false;

 int nPaletteEntries=GetPalEntries(InfoHeader);
 int nColorTable=256 * sizeof(RGBQUAD);
 int nInfo=sizeof(BITMAPINFOHEADER)+nColorTable;
 int nPixels=FileHeader.bfSize-FileHeader.bfOffBits;

 pInfo=(BITMAPINFO*) new BYTE[nInfo];
 memcpy(pInfo, &InfoHeader, sizeof(BITMAPINFOHEADER));
 file.Read(((BYTE *)pInfo) + sizeof(BITMAPINFOHEADER), nColorTable);
 pPixels=new BYTE[nPixels];
 file.Seek(FileHeader.bfOffBits, CFile::begin);
 file.Read(pPixels, nPixels);
 return true;
}

int cDib::GetPalEntries(BITMAPINFOHEADER &InfoHeader)
{
 int nReturn;
 if(InfoHeader.biClrUsed==0)
 {
  nReturn=(1<<InfoHeader.biBitCount);
 }
 else nReturn=InfoHeader.biClrUsed;
 return nReturn;
}

void cDib::Draw(CDC *pDC, CRect r)
{
 HDC hdc=pDC->GetSafeHdc();
 if(pInfo)
 {
  StretchDIBits(hdc, 0,0, r.Width(), r.Height(), //GetWidth(), GetHeight(),
   0,0, GetWidth(), GetHeight(),
   GetPixelPtr(),
   GetHeaderPtr(),
   DIB_RGB_COLORS,
   SRCCOPY);
 }
}

Espero que te funcione... ya dir�s alguna cosa... saludos.

--
Crist�bal Tello
progwin@terra.es
http://www.lawebdelprogramador.com/cursos/progwinc.php
Technical Details
Message-ID: <9m6gp9$if7$1@talia.mad.ttd.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!fu-berlin.de!newsfeed.bcn.ttd.net!news.mad.ttd.net!not-for-mail
References: <2tdh7.38943$lo5.891874@telenews.teleline.es>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f53ec,dc5ae025bf5d8fa8
X-Google-Attributes: gidf53ec,public
X-Google-Thread: 10d088,dc5ae025bf5d8fa8
X-Google-Attributes: gid10d088,public
X-Google-Thread: 10a068,dc5ae025bf5d8fa8
X-Google-Attributes: gid10a068,public
X-Google-ArrivalTime: 2001-08-24 14:36:56 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!fu-berlin.de!newsfeed.bcn.ttd.net!news.mad.ttd.net!not-for-mail
From: "Crist�bal Tello" <progwin@terra.es>
Newsgroups: es.comp.os.ms-windows.programacion,es.comp.lenguajes.c++,microsoft.public.es.vc
Subject: RE: cargar BMP desde archivo con Visual C++
Date: Fri, 24 Aug 2001 23:36:30 +0200
Organization: Telefonica Transmision de Datos
Lines: 106
Message-ID: <9m6gp9$if7$1@talia.mad.ttd.net>
References: <2tdh7.38943$lo5.891874@telenews.teleline.es>
NNTP-Posting-Host: 213-99-103-44.uc.nombres.ttd.es
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200