Page 1 of 1

How can I load bitmap from memory??

PostPosted: Apr 19, 2002 @ 8:56am
by cat48
Hi ^^

Thanks for last time reply..
I have a another question..
I want to load png files..
I already got a Bitmap handle, BITMAPINFOHEADER and raw data from png file.
ann then I tried Loadbitmap(resourceID, BITMAPINFOHEADER, data), But it didn't work.
and if bitsperpixel value is 16, Loadbitmap return 0.
Plase Help me :cry:

CCompImage* m_pImage; // Compressed Image
m_pImage = new CCompImage;
HBITMAP hBitmap = NULL;

m_pImage->Load(dc.GetSafeHdc(), _T("xxx.png"));
hBitmap = m_pImage->GetBitmapHandle();

CBitmap m_bitmap;
m_bitmap.Detach();
m_bitmap.Attach(hBitmap);

BITMAP bm;
m_bitmap.GetBitmap(&bm);

PBITMAPINFO bi = CreateBitmapInfoStruct(hBitmap);

if(!m_pGapi->LoadBitmap(m_backMap.m_ImgMap, &bi->bmiHeader, (BYTE*)bm.bmBits))
return FALSE;

bmp file....

PostPosted: Apr 19, 2002 @ 11:11am
by cat48
This Source is not work, too.
So I don't know exactly that what's wrong..
When I Run LoadBitmap Function, and "Access Violation Error!!!1"

Please Help me

CFile file;
if (!file.Open(_T("\\My Documents\\xxx.bmp"), CFile::modeRead))
return FALSE;


DWORD dwFileStart = file.GetPosition();

BITMAPFILEHEADER BmpFileHdr;
int nBytes;
nBytes = file.Read(&BmpFileHdr, sizeof(BmpFileHdr));
if (nBytes != sizeof(BmpFileHdr))
{
TRACE0("Failed to read file header\n");
return FALSE;
}

BITMAPINFOHEADER BmpInfo;
nBytes = file.Read(&BmpInfo, sizeof(BITMAPINFOHEADER));
if (nBytes != sizeof(BITMAPINFOHEADER))
{
TRACE0("Failed to read BITMAPINFOHEADER\n");
return FALSE;
}

// Check that we have a real Windows DIB file.
if (BmpInfo.biSize != sizeof(BITMAPINFOHEADER))
{
TRACE0(" File is not a Windows DIB\n");
return FALSE;
}

// Allocate the memory for the bits and read the bits from the file.
BYTE* pBits = (BYTE*) malloc(nBitsSize);
if (!pBits)
{
TRACE0("Out of memory for DIB bits\n");
return FALSE;
}

// Seek to the bits in the file.
file.Seek(dwFileStart + BmpFileHdr.bfOffBits, CFile::begin);

// read the bits
nBytes = file.Read(pBits, nBitsSize);
if (nBytes != nBitsSize)
{
TRACE0("Failed to read bits\n");
free(pBits);
return FALSE;
}

// Everything went OK.
BmpInfo.biSizeImage = nBitsSize;

if(!m_pGapi->LoadBitmap(m_backMap.m_ImgMap, &BmpInfo, pBits))
return FALSE;
free(pBits);

PostPosted: Apr 22, 2002 @ 2:49am
by CapesDev