M
mrai rasouli
Guest
void CMRSMATHDlg::Loadit(TCHAR *destination, CDC &memdc)
{
CImage img;
PBITMAPINFO bmi;
bool reverse=false;
BITMAPINFOHEADER Info;
BITMAPFILEHEADER bFileHeader;
CBitmap *bm=new CBitmap();
CFile file2;
file2.Open(destination, CFile::modeRead | CFile::typeBinary);
file2.Read(&bFileHeader, sizeof(BITMAPFILEHEADER));
file2.Read(&Info, sizeof(BITMAPINFOHEADER));
BYTE ch;
int width = Info.biWidth;
int height = Info.biHeight;
if (height > 0)
{
reverse = true;
}
if (height<0)
height = -height;
int size1 = width*height * 3;
int size2 = ((width * 24 + 31) / 32) * 4 * height;
int gap = (size2 - size1) / height;
BYTE * buffer = (BYTE *)GlobalAlloc(GPTR, size2);
BYTE * gbuffer = (BYTE *)GlobalAlloc(GPTR, gap);
memset(gbuffer, 0, gap);
//////////////////////////
HGDIOBJ old;
unsigned char alpha = 0;
int z = 0;
z = 0;
for (int y = 0;y < height;y++)
{
for (int x = 0;x < width;x++)
{
file2.Read(&ch, 1);
if (reverse)
z = (((height - 1 - y)*width) + (x)) * 3;
else
z = ((y*width) + x) * 3;
buffer[z] = ch;
z++;
file2.Read(&ch,1);
buffer[z] = ch;
z++;
file2.Read(&ch,1);
buffer[z] = ch;
z++;
}
file2.Read(gbuffer,gap);
}
//bm.CreateCompatibleBitmap(&memdc, width, height);
BITMAPINFO info;
ZeroMemory(&info, sizeof(BITMAPINFO));
info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info.bmiHeader.biBitCount = 24;
info.bmiHeader.biPlanes = 1;
info.bmiHeader.biCompression = BI_RGB;
info.bmiHeader.biSizeImage = size1;
info.bmiHeader.biWidth = width;
info.bmiHeader.biHeight = height;
info.bmiHeader.biClrUsed = 0;
CImage d;
//////////////////////////////////////triangle not run
//bm.Attach(d.Detach());
//int r=SetDIBits(memdc.GetSafeHdc(),(HBITMAP)bm,0, height, buffer,&info, DIB_RGB_COLORS);//////line1
//d.Attach((HBITMAP)bm->Detach());//one soloution forsave not true run ;fail!///////////////////line2 two lines run with together
//////////////AFTER YOU RUN ACHIEVE TO FAILED!
//bm->CreateBitmap(width,height,1,24,buffer);//not run is failed one line
//bm->SetBitmapBits(size1,buffer);//solution two fail one line/////////////////////////////////////////////
bm->CreateCompatibleBitmap(GetDC(),width,height);//line one
//bm->SetBitmapBits(size1,buffer);//line two
////////////////////////////////////////////////////////////////////////////////////////////////////
d.Save(L"c:\\KRI.BMP");/////////please view file not bitblt
old = memdc.SelectObject(&bm);
///////////////////////////
bm->SetBitmapBits(size1, buffer);
GetDC()->BitBlt(1,95, width, height, &memdc, 0, 0, SRCCOPY);
memdc.SelectObject(&old);
memdc.ReleaseAttribDC();
bm->DeleteObject();
free(&bm);
GlobalFree(buffer);
}
Continue reading...
{
CImage img;
PBITMAPINFO bmi;
bool reverse=false;
BITMAPINFOHEADER Info;
BITMAPFILEHEADER bFileHeader;
CBitmap *bm=new CBitmap();
CFile file2;
file2.Open(destination, CFile::modeRead | CFile::typeBinary);
file2.Read(&bFileHeader, sizeof(BITMAPFILEHEADER));
file2.Read(&Info, sizeof(BITMAPINFOHEADER));
BYTE ch;
int width = Info.biWidth;
int height = Info.biHeight;
if (height > 0)
{
reverse = true;
}
if (height<0)
height = -height;
int size1 = width*height * 3;
int size2 = ((width * 24 + 31) / 32) * 4 * height;
int gap = (size2 - size1) / height;
BYTE * buffer = (BYTE *)GlobalAlloc(GPTR, size2);
BYTE * gbuffer = (BYTE *)GlobalAlloc(GPTR, gap);
memset(gbuffer, 0, gap);
//////////////////////////
HGDIOBJ old;
unsigned char alpha = 0;
int z = 0;
z = 0;
for (int y = 0;y < height;y++)
{
for (int x = 0;x < width;x++)
{
file2.Read(&ch, 1);
if (reverse)
z = (((height - 1 - y)*width) + (x)) * 3;
else
z = ((y*width) + x) * 3;
buffer[z] = ch;
z++;
file2.Read(&ch,1);
buffer[z] = ch;
z++;
file2.Read(&ch,1);
buffer[z] = ch;
z++;
}
file2.Read(gbuffer,gap);
}
//bm.CreateCompatibleBitmap(&memdc, width, height);
BITMAPINFO info;
ZeroMemory(&info, sizeof(BITMAPINFO));
info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info.bmiHeader.biBitCount = 24;
info.bmiHeader.biPlanes = 1;
info.bmiHeader.biCompression = BI_RGB;
info.bmiHeader.biSizeImage = size1;
info.bmiHeader.biWidth = width;
info.bmiHeader.biHeight = height;
info.bmiHeader.biClrUsed = 0;
CImage d;
//////////////////////////////////////triangle not run
//bm.Attach(d.Detach());
//int r=SetDIBits(memdc.GetSafeHdc(),(HBITMAP)bm,0, height, buffer,&info, DIB_RGB_COLORS);//////line1
//d.Attach((HBITMAP)bm->Detach());//one soloution forsave not true run ;fail!///////////////////line2 two lines run with together
//////////////AFTER YOU RUN ACHIEVE TO FAILED!
//bm->CreateBitmap(width,height,1,24,buffer);//not run is failed one line
//bm->SetBitmapBits(size1,buffer);//solution two fail one line/////////////////////////////////////////////
bm->CreateCompatibleBitmap(GetDC(),width,height);//line one
//bm->SetBitmapBits(size1,buffer);//line two
////////////////////////////////////////////////////////////////////////////////////////////////////
d.Save(L"c:\\KRI.BMP");/////////please view file not bitblt
old = memdc.SelectObject(&bm);
///////////////////////////
bm->SetBitmapBits(size1, buffer);
GetDC()->BitBlt(1,95, width, height, &memdc, 0, 0, SRCCOPY);
memdc.SelectObject(&old);
memdc.ReleaseAttribDC();
bm->DeleteObject();
free(&bm);
GlobalFree(buffer);
}
Continue reading...